几种常见的字符串用法
package test;
public class test6 {
public static void main(String[] args){
//1
String s = String.join("/","s","m","n");
System.out.println(s);
//2
String greeting = "hello";
String h = greeting.substring(0,3);
//3
if(greeting.equals("hello")){
System.out.println("相同");
}else{
System.out.println("不相同");
}
//4
if(greeting.equalsIgnoreCase("HELLO")){
System.out.println("相同");
}else{
System.out.println("不相同");
}
//5
System.out.println(s+"\n"+greeting);
//6
System.out.println(greeting.length());
}
}
结果:
s/m/n
相同
相同
s/m/n
5
空串和null串的区别
空串长度为0,内容为空,是一个Java对象
String变量存放null时,表示目前没有任何对象与该变量关联