本文共 5867 字,大约阅读时间需要 19 分钟。
public class OODemo12{ public static void main(String args[]){ String str1 = "abc" ; String str2 = new String("abc") ; String str3 = str2 ; } }; |
public class OODemo12{ public static void main(String args[]){ String str1 = "abc" ; String str2 = new String("abc") ; String str3 = str2 ; System.out.println(str1==str2) ; // false System.out.println(str1==str3) ; // false System.out.println(str3==str2) ; // true } }; |
public class OODemo13{ public static void main(String args[]){ String str1 = "abc" ; String str2 = new String("abc") ; String str3 = str2 ; System.out.println(str1.equals(str2)) ; // true System.out.println(str1.equals(str3)) ; // true System.out.println(str3.equals(str2)) ; // true } }; |
public class OODemo14{ public static void main(String args[]){ String str1 = "abc" ; } }; |
public class OODemo14{ public static void main(String args[]){ String str1 = new String("abc") ; } }; |
public class OODemo14{ public static void main(String args[]){ String str1 = "abc" ; str1 += "bcd" ; System.out.println(str1) ; } }; |
public class OODemo15{ public static void main(String args[]){ String str1 = "abc" ; String str2 = "abc" ; System.out.println(str1==str2) ; } }; |
public class OODemo28{ public static void main(String args[]){ String str1 = "a" ; for(int i=0;i<100;i++){ str1 += i ; } System.out.println(str1) ; } }; |
public class OODemo16{ public static void main(String args[]){ String str1 = "abcfdafdsadafsdfdssdfa" ; System.out.println(str1.length()) ; } }; |
public class OODemo17{ public static void main(String args[]){ String str1 = "abcfdafdsadafsdfdssdfa" ; char c[] = str1.toCharArray() ; for(int i=0;i<c.length;i++){ System.out.print(c[i]+"\t") ; } } }; |
public class OODemo18{ public static void main(String args[]){ char c[] = {'a','b','c','d','e'} ; System.out.print(new String(c)) ; } }; |
public class OODemo19{ public static void main(String args[]){ String str = "ABCDEFG" ; System.out.println(str.indexOf("ABC")) ; if(str.indexOf("ABC")!=-1){ System.out.println(" 查到了指定内容。 ") ; }else{ System.out.println(" 没有查到指定内容。 ") ; } } }; |
public class OODemo20{ public static void main(String args[]){ String str = "ABCDEFG" ; System.out.println(str.substring(0,3)) ; } }; |
public class OODemo21{ public static void main(String args[]){ String str = "A:B:C" ; String s[] = str.split(":") ; for(int i=0;i<s.length;i++){ System.out.println(s[i]) ; } } }; |
public class OODemo22{ public static void main(String args[]){ String str = "hello world!!!" ; System.out.println(str.replace("o","x")) ; } }; |
public class OODemo23{ public static void main(String args[]){ String str = "**hello**" ; System.out.println(str.startsWith("**")) ; System.out.println(str.endsWith("**")) ; } }; |
public class OODemo24{ public static void main(String args[]){ String str = "MIKE:70|JONES:80|TOM:75" ; System.out.println("\"\'\\") ; // 拆分两次 String s1[] = str.split("\\|") ; for(int i=0;i<s1.length;i++){ String s2[] = s1[i].split(":") ; System.out.println(s2[0]+" --> "+s2[1]) ; } } }; |
public class OODemo25{ public static void main(String args[]){ String str = "helwo" ; System.out.println(str.charAt(2)) ; } }; |
public class OODemo26{ public static void main(String args[]){ char c[] = {'h','e','l','w','o'} ; System.out.println(new String(c,1,3)) ; } }; |
public class OODemo27{ public static void main(String args[]){ String str1 = "abc" ; String str2 = "ABC" ; System.out.println(str1.equalsIgnoreCase(str2)) ; } }; |
class Demo{ int x ; }; public class Demo29{ public static void main(String args[]){ Demo d1 = new Demo() ; d1.x = 30 ; fun(d1) ; System.out.println(d1.x) ; } public static void fun(Demo d2){ d2.x = 50 ; } }; |
public class Demo30{ public static void main(String args[]){ String str = "abc" ; fun(str) ; System.out.println(str) ; } public static void fun(String s){ s = "bcd" ; } }; |
class Demo{ String name ; }; public class Demo31{ public static void main(String args[]){ Demo d = new Demo() ; d.name = "abc" ; fun(d) ; System.out.println(d.name) ; } public static void fun(Demo x){ x.name = "bcd" ; } }; |