1 public class testList { 2 public static void main(String[] args){ 3 java.util.List<String> ls = new java.util.ArrayList<>(); 4 ls.add("A"); 5 ls.add("B"); 6 ls.add("C"); 7 String[] str = {"A","B","C","D"}; 8 for(int i=0;i<str.length;i++){ 9 ls.add(str[i]); 10 } 11 java.util.Set<String> set = new java.util.TreeSet<>(ls); 12 java.util.List<String> lsr = new java.util.ArrayList<>(); 13 lsr.addAll(set); 14 System.out.println(lsr.toString()); 15 } 16 }
打印结果:[A, B, C, D]
时间: 2024-11-25 13:53:17