1. List<String> 转 List<integer> 、List<Long>
1 import java.util.ArrayList; 2 import java.util.List; 3 import java.util.stream.Collectors; 4 5 public class Test1 { 6 public static void main(String []args){ 7 //List<String> 8 List<String> listString =new ArrayList(); 9 listString.add("1111"); 10 listString.add("2222"); 11 listString.add("3333"); 12 13 //listString 转List<Integer> 14 List<Integer> listInteger = listString.stream().mapToInt(Integer::parseInt).boxed().collect(Collectors.toList()); 15 16 //listString 转List<Long> 17 List<Long> listLong = listString.stream().mapToLong(Long::parseLong).boxed().collect(Collectors.toList()); 18 19 } 20 }
2. List<Object> 转 List<String>
package cn.dotfashion.soa.ops.job; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class Test12 { public static void main(String []args){ //List<Object> List<Object> listObject =new ArrayList<>(); listObject.add("1111"); listObject.add("2222"); listObject.add("3333"); //List<Object> 转 List<String> List<String> listString = Arrays.asList(listObject.toArray(new String[listObject.size()])); } }
标签:listString,java,List,list,util,add,泛型,import From: https://www.cnblogs.com/whycai/p/16974817.html