String trim () :去掉字符串两端的空格
String [] split (String str):按照指定符号分割字符串
Code:
String s1 = "helloworld";
String s2 = " helloworld ";
System.out.println(s1.trim()); //helloworld
System.out.println(s2.trim()); //helloworld
String s4 = "aa,bb,cc,dd";
String [] strarray = s4.split(","); //根据,分割字符串
for (int x=0;x<strarray.length;x++) { //遍历数组
System.out.println(strarray[x]);
}
本文介绍了Java中使用String.trim()去除字符串两端空格的方法,以及如何利用String.split()按指定符号分割字符串,通过实例展示了基本用法。
978

被折叠的 条评论
为什么被折叠?



