String类的一些函数

/**
*
* @author crane
*
*split方法用于拆分字符串,参数是拆分字符串的分隔符
*str.split(" ");
*参数为空则按字符全部拆分
*/
public class StringDemo6 {
public static void main(String args[]) {
String str = "hello yootk nihao mldn";
String result[] = str.split(" ");
for(int x = 0; x < result.length; x++) {
System.out.print(result[x]+" 、");
}
System.out.println("");

String resultA[] = str.split("");
for(int x = 0; x < resultA.length; x++) {
System.out.print(resultA[x] + "、");
}
}
}

猜你喜欢

转载自www.cnblogs.com/diaohuluwa/p/10881596.html