能用代碼說話的,覺不打字描述java
public static void main(String[] args){ //List<Long> to List<String> List<Long> numList1 = new ArrayList<>(); numList1.add(1L); numList1.add(2L); numList1.add(3L); List<String> strList1 = numList1.stream().map(String::valueOf).collect(Collectors.toList()); System.err.println("List<Long> to List<String> ------::"+JSON.toJSON(numList1)); //List<String> to List<Long> List<String> strList2 = new ArrayList<>(); strList2.add("1"); strList2.add("2"); strList2.add("3"); List<Long> numList2 = strList2.stream().map(s -> Long.parseLong(s.trim())).collect(Collectors.toList()); System.err.println("List<String> to List<Long>------::"+JSON.toJSON(numList2)); }
結果以下圖所示:code