* public String():创建String对象
* public String(byte[] bytes):把字节数组转成字符串。
* public String(byte[] bytes,int index,int length):把字节数组中的一部分转成字符串
* public String(char[] value):把字符数组转成字符串
* public String(char[] value,int index,int count):把字符数组的一部分转成字符串
* public String(String original):把字符串转成字符串
注意问题:
* 而toString()方法默认输出的是包名...类名@哈希值的十六进制。
* 如果,你用输出语句输出一个对象名称的时候,发现不是这个格式,说明了该类重写了toString()方法。
* 2:返回此字符串的长度
* public int length()
*
二、String s = new String("hello")和String s ="hello"; 的区别:
==:比较的是引用类型,比较的是地址值即:
(s1 == s2); // false
equal():默认比较的是地址值。String类重写了equals()方法,该方法的作用是比较字符串的内容是否相同
((s2)); // true
三、 * 字符串变量相加:先开空间,再加内容
* 字符串常量相加:先加,再找,没有再开空间
String s1 = "hello";
String s2 = "world";
String s3 = "helloworld";
String s4 = s1 + s2;
String s5 = "hello"+"world";即s4和s5的区别。
四、String类的判断功能:
* boolean equals(Object obj):比较字符串的内容是否相同,严格区分大小写
* boolean equalsIgnoreCase(String str):比较字符串的内容是否相同,不考虑大小写
* boolean contains(String str):判断是否包含指定的小串
* boolean startsWith(String str):判断是否以指定的字符串开头
* boolean endsWith(String str):判断是否以指定的字符串结尾
* boolean isEmpty():判断字符串的内容是否为空
五、String类的获取功能:
* int length():返回字符串的长度。字符的个数。
* char charAt(int index):返回字符串中指定位置的字符。
* int indexOf(int ch):返回指定字符在字符串中第一次出现的位置
* int indexOf(String str):返回指定字符串在字符串中第一次出现的位置
* int indexOf(int ch,int fromIndex):返回指定字符从指定位置开始在字符串中第一次出现的位置
* int indexOf(String str,int fromIndex):返回指定字符串从指定位置开始在字符串中第一次出现的位置
* String substring(int start):返回从指定位置开始到末尾的子串
* String substring(int start,int end):返回从指定位置开始到指定位置结束的子串----注意左包右不包
六、String的转换功能:
* byte[] getBytes():把字符串转换为字节数组
* char[] toCharArray():把字符串转换为字符数组
* static String valueOf(char[] chs):把字符数组转成字符串
* static String valueOf(int i):把int类型的数据转成字符串
* 把任意类型转换为字符串的方法。
* String toLowerCase():把字符串转小写
* String toUpperCase():把字符串转大写
* String concat(String str):字符串的连接
替换功能:
* String replace(char old,char new)
* String replace(String old,String new)
去除字符串两空格:
* String trim()
按字典顺序比较两个字符串 a-z
* int compareTo(String str)
* int compareToIgnoreCase(String str)