String str1 = new String();// 说明字符串没有任何内容
使用字符数组创建字符串对象
char[] charArray = {'A','B','C'};
String str2 = new String(charArray);
根据字节数组来创建字符串对象 A-->65
byte[] byteArray = {65,66,67};
String str3 = new String(byteArray);
拼接字符串
String str2 = "Hello";
String str3 = "World";
String concat = str2.concat(str3);
获取指定索引处的单个字符 索引的起始值0
char c = "Hello".charAt(1);
查找参数字符串在该字符串当中第一次出现的索引值 indexOf(String str)
int i = str.indexOf("121");
获取str4中的从w开始后面的全部字符串内容
int i1 = str4.indexOf("W");
String substring = str4.substring(i1);
截取开始索引到结束索引的内容
String substring1 = str4.substring(4, 10);
把字符串转换成字节数组
byte[] bytes = str.getBytes();
字符串内容的替换
String str2 = "Nice to meet you";
String o = str2.replace("o", "*");
浙公网安备 33010602011771号