----------- android培训、java培训、java学习型技术博客、期待与您交流! ------------
class Person
{
public String name = "jack";
}
class Demo2
{
// 基本数据类型改值
public static void changeData( int x ){
x = 1;
System.out.println( "x="+x );
}
public static void changeData( double y ){
y = 10.1;
}
// 数组的修改
public static void changeDate( int[] is ){
is[0] = 10;
}
public static void changeData( Person p ){
p.name = "lucy";
}
// String的修改
public static void changeData( String str ){
str = "lii";
}
public static void main(String[] args)
{
int x = 0;
changeData( x );
System.out.println( "x="+x );
double y = 12.1;
changeData(y);
System.out.println( "y="+y);
int[] is = new int[]{1,2,3};
System.out.println( Arrays.toString(is) ); // [ 1,2,3 ]
changeDate(is);
System.out.println( Arrays.toString(is) ); // [ 10,2,3 ]
Person p = new Person(); // jack
System.out.println( "name= "+p.name);
changeData(p);
System.out.println( "name= "+p.name);
String str = new String("jnb");
System.out.println( "str= "+str );
changeData(str);
System.out.println( "str= "+str );
}
}
/**
底层采用的是长度可以变的char数组。
String不可变。
*/
----------- android培训、java培训、java学习型技术博客、期待与您交流! ------------