Java记录参数传递和split

class Main {
public static void swap(Integer i, Integer j) {
      Integer temp = new Integer(i);
      i = j;
      j = temp;
   }
   public static void main(String[] args) {
      Integer i = new Integer(10);
      Integer j = new Integer(20);
      swap(i, j);
      System.out.println("i = " + i + ", j = " + j);
   }
}
  //i = 10, j = 20Java 函数参数通过值传递。


class intWrap {
   int x;
} 
public class Main { 
    public static void main(String[] args) {
       intWrap i = new intWrap();
       i.x = 10;
       intWrap j = new intWrap();
       j.x = 20;
       swap(i, j);
       System.out.println("i.x = " + i.x + ", j.x = " + j.x);
    } 
    public static void swap(intWrap i, intWrap j) {
       int temp = i.x;
       i.x = j.x;
       j.x = temp;
    }
}
 // i.x = 20, j.x = 10
类按引用传递
class Test
{
    public void demo(String str)
    {
        String[] arr = str.split(";");//split() 根据指定的规则或分隔符来分隔字符串,并返回数组。
        for (String s : arr)
        {
            System.out.println(s);
        }
    }
 
    public static void main(String[] args)
    {
        char array[] = {'a', 'b', ' ', 'c', 'd', ';', 'e', 'f', ' ', 
                        'g', 'h', ';', 'i', 'j', ' ', 'k', 'l'};
        String str = new String(array);//String 类有一个内置的构造函数 String(character_array),它可以将字符数组初始化成一个字符串
        Test obj = new Test();
        obj.demo(str);
    }
}
原文地址:https://www.cnblogs.com/zhuimingzhenbai/p/12692717.html