package util.test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class TestPhone {
public static void main(String[] args) {
String[] telephone = { "123456789" };
// Arrays.asList(telephone)会返回一个定长类;把String[]转为List<String>
List<String> teles = new ArrayList<String>(Arrays.asList(telephone));
teles.add("1234567890");
// 去重
List<String> finDis = teles.stream().distinct().collect(Collectors.toList());
// 把List<String>转为String[]
String[] finphone = new String[finDis.size()];
finDis.toArray(finphone);
int lenth = finphone.length;
System.out.println("--->>最后结果长度: " + lenth);
System.out.println("--->>最后结果长度: " + finphone[0]);
System.out.println("--->>最后结果长度: " + finphone[1]);
System.out.println("--->>最后结果长度: " + finphone);
String name = "中国_北京市_大兴区";
String[] ss = name.substring(3).split("_");
int lenth1 = ss.length;
System.out.println("--->>最后结果长度: " + lenth1);
for (int i = 0; i < lenth; i++) {
System.out.println("--->>最后结果长度: " + ss[i]);
}
}
}
String数组与List<String>相互转化
最新推荐文章于 2024-07-30 18:30:21 发布