StringBuffer类是不是字符串?
int[] a=int []{1,2,3,4,5};
int[] a={1,2,3,4,5}
//有什么区别?
String s1=new String("Hello World!");
String s2=new String("Hello World!");
//创建了几个String类的实例,都在哪?
int[] a=int []{1,2,3,4,5};
int[] a={1,2,3,4,5}
//有什么区别?
String s1=new String("Hello World!");
String s2=new String("Hello World!");
//创建了几个String类的实例,都在哪?
这种定义 编译能通过吗?
再怎么也是 int [] b=new int[]{1,2,3};吧2:new 出来的对象必然都是在堆上public class StringTest { /**
* @param args
*/
public static void main(String[] args) {
String s1= new String("hellow wrold");
String s2=new String ("hellow wrold");
System.out.println(s1==s2);
System.out.println(s1.equals(s2));
String s3="hellow wrold";
String s4="hellow wrold";
System.out.println(s3==s4);
System.out.println(s3.equals(s4));
}}false
true
true
true
写法有区别,功能都一样。
1个,字符串池
int[] a={1,2,3,4,5}
//这两行代码有什么区别?
写法有区别,功能都一样。为了程序员少敲键盘用的.
2个,Heap中(注意如果是 S="string", 是在字符串池,和new的区别就在于此)
StringBuffer是个字符串缓冲。可以加快程序的运行速度 这个是线程安全的 ,非线程安全的用StringBuilder问题2 int[] a=int []{1,2,3,4,5};
int[] a={1,2,3,4,5}
//有什么区别?
没用区别 下面的这个是简略学法 建议用上面的那个问题3 String s1=new String("Hello World!");
String s2=new String("Hello World!");
//创建了几个St……创建了2个 记住 new了之后一定会在堆区创建一个新的对象