JAva,Stringパラメータの実パラメータ値は変わらず,equalsと==浅析
1643 ワード
public class Test {
public static void test(String str) {
str = "World";
}/// str , string , ( )
public static void main(String[] args) {
String string = "Hello";
test(string);
System.out.println(string);hello
String s = "abc";
String t = "a";
String u = s.substring(0, 1);
// System.out.println(s.substring(0, 1));
System.out.println(t.equals(s.substring(0, 1))); // //True
System.out.println(t == s.substring(0, 1));// /false
System.out.println(t.equals(u)); //True
System.out.println(t == u); //false
System.out.println(u.equals(s.substring(0, 1))); // //True
System.out.println(u == s.substring(0, 1));// /false //s.substring(0, 1); String
System.out.println(s.substring(0, 1).equals(s.substring(0, 1)));///true
System.out.println(s.substring(0, 1) == s.substring(0, 1));///false
Test t1 = new Test();///t1 Test 1
Test t2 = new Test();//t2 Test 2
System.out.println(t1.equals(t2)); //false
System.out.println(t1 == t2); //false
Test t3 = t1;//t1 t3 Test 1
System.out.println(t1.equals(t3)); //true ///
System.out.println(t1 == t3); //true
System.out.println(t2.equals(t3)); //false
System.out.println(t2 == t3); //false
// JAVA Object , Object equals ,
// , ,
// String,Integer,Date equals ,
// ==
// equals(), String,Integer,Date , ;
}
}
Stringについて str 3="abc".....のequals(),==比較的簡単すぎて書かない