String

// char转String (1)
char[] helloArray = { 'a', 'b', 'c'};
String helloString = new String(helloArray);

// char转String (2)
char[] helloArray = { 'a', 'b', 'c'};
String helloString = "";
helloString = helloString.copyValueOf( helloArray );

// 从下标2位置获取, 获取6个
helloString = helloString.copyValueOf( helloArray, 2, 6 );

// 连接字符串, 省内存
s1.concat(s2)

// 格式化输出
System.out.printf("%s%s",s1,s2);
String str = String.format("%s%s",s1,s2);

// 获取字符串下标位
s1.charAt(2)

// 字符串复制到char中
String s1 = "123456";
char[] s2 = new char[6];
//字符串起始位,字符串结束位,目标char,目标char开始位
s1.getChars(0, 6, s2, 0);

// 返回指定字符在字符串中第一次出现处的索引 (可以用ASCII码查找)
String s1 = "12345634";
int index = s1.indexOf("3");

// 字符串切割, 支持正则表达式
s1.split("-")
// 只切割2份
s1.split("-",2)

// 判断字符串是否包含子串
// s1中是否含有"Run"
s1.contains("Run")

// 字符串自动转换为char
String s1 = "1abc563";
char[] chars = s1.toCharArray();

// 判断是否为空
s1.isEmpty()

版权声明:本文为a1334933655原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/a1334933655/article/details/121788179