zoukankan      html  css  js  c++  java
  • 1、向集合添加元素是否能成功。。。

     1 package com.hanqi;
     2 
     3 import java.util.ArrayList;
     4 import java.util.Collections;
     5 import java.util.HashSet;
     6 import java.util.List;
     7 import java.util.TreeSet;
     8 
     9 public class JKL {
    10 
    11         ArrayList<String> lis = new ArrayList<String>();
    12         lis.add("A");
    13         lis.add("a");
    14         lis.add("c");
    15         lis.add("C");
    16         lis.add("a");
    17         Collections.addAll(lis, "e", "f", "g", "h", "i");
    18 
    19         System.out.println("ArrayList输出 " + lis);
    20 
    21         HashSet<String> hs = new HashSet<String>();
    22         
    23         hs.add("A");
    24         hs.add("a");
    25         hs.add("c");
    26         hs.add("C");
    27         hs.add("a");
    28 
    29         Collections.addAll(hs, "e", "f", "g", "h", "i");
    30 
    31         System.out.println("HashSet输出 " + hs);
    32 
    33         TreeSet<String> ss = new TreeSet<String>();
    34         
    35         ss.add("A");
    36         ss.add("a");
    37         ss.add("c");
    38         ss.add("C");
    39         ss.add("a");
    40         
    41         Collections.addAll(ss, "e", "f", "g", "h", "i");// 可以重复,有序大写在前,小写在后,以顺序排列
    42         
    43         System.out.println("TreeSet输出 " + ss);
    44 
    45 }
    46 }    

    HashSet输出 [f, g, e, c, A, C, a, h, i]
    TreeSet输出 [A, C, a, c, e, f, g, h, i]

  • 相关阅读:
    codeforces 938 C. Constructing Tests
    codeforces 981 C.Useful Decomposition
    Wannafly 挑战赛16 A 取石子
    codeforces 873 D. Merge Sort(分治)
    lightoj 1158
    lightoj 1226
    lightoj 1382
    lightoj 1283
    hdu 5445 Food Problem (多重背包)
    light 1205
  • 原文地址:https://www.cnblogs.com/as1234as/p/5152815.html
Copyright © 2011-2022 走看看