private

  1. 私有的方法和属性,私有属性必须提供对外的getter和setter方法,相当于多一层拦截。

String

1
2
3
4
5
6
7
String a = "123";   //新建一块对内存,并放入对象池之中
String b = new String("123"); //先执行内存空间开辟“123”,如果对象池之中已经存在则直接使用,然后执行new,有开辟一块新的堆内存存放“123”,原来的“123”变成垃圾
System.out.println(a == b); //false 地址的比较
System.out.println(a.equals(b)); //值的比较

String c = new String("123").intern(); //将新建的对象“123”放入对象池之中
System.out.println(a == c); //true 地址的比较,同一块对象池

compareTo方法

1
2
3
4
5
6
7
8
9
10
11
12
String a = "A";
String b = "a";
System.out.print(b.compareTo(a)); //32 比较大小关系,返回差值,可以用来比较中文

String c = "abcd";
Boolean d = c.contains("ab"); //true 判断是否包含“ab”

String e = "192.168.1.1";
String f[] = e.split("\\."); //只能是正则,必须转义
for(int i = 0; i < f.length; i++) {
System.out.println(f[i]);
}

this调用构造方法:支持类构造方法的互相调用,如:this(1, “string”)