1.用==还是用equals() 除非判断两个字符串是否为同一个对象,否则统一使用equals()
2.对于安全敏感信息使用char[]
3.字符串换整数,前提是这个字符串为整数,int a = Integer.parseInt(“100”)
4.String、StringBuffer、StringBuilder。一般字符串拼接使用StringBuilder,因为效率高;
StringBuffer是同步的,是线程安全的,他有个同步的过程,所以比StringBuilder慢。
5.concat() 方法用于将指定的字符串参数连接到字符串上。eg:
String s1 = “hello”;
String s2 = s1.concat(“world”);
System.out.println(s2);
输出为 helloworld
6.charAt(n)用法,截取第n字符。eg:
输出为w
7.replace(“m”,“n”),将字符串中的m换成n。eg:
输出为:hellAwArld