java
复制代码
package com.qc.字符串;
import java.util.Arrays;
public class Test {
public static void main(String[] args) {
// String x="hello";//字符串 char[]
// x = x+"demo";//字符串拼接
// x=x+24+50;
// x=x+true;
// System.out.println(x);//hellodemo2450true
//
// x.replace("o", "li");//o被替换为li
// System.out.println(x);
//
// String[] arr=x.split("");//分割
// System.out.println(Arrays.toString(arr));//[h, e, l, l, o, d, e, m, o, 2, 4, 5, 0, t, r, u, e]
//
// int index=x.indexOf("dem");//返回子串第一个字母的下标
// System.out.println(index);//没有返回-1
//
// System.out.println(x.substring(2,5));//返回子串,左闭右开
// System.out.println(x.substring(2));//子串下标从2开始
// //java不可变字符串
// String s1="hello";//字符串常量池里
// String s2="hello";
// String s3=new String("hello");
// String s4=new String("hello");
// //== 引用类型判断指向是否相同 基本类型判断值是否相等
// System.out.println(s1==s2);
// System.out.println(s3==s2);
// System.out.println(s3==s4);
//
// System.out.println(s1.equals(s2));
// System.out.println(s2.equals(s3));
// System.out.println(s3.equals(s4));
String s1=null;//null串没有任何空间
String s2="";//空串有指向
System.out.println(s1);
System.out.println(s2);
//API:提供的各种方法
}
}