hitechr

List的初始化方法

方法一

    List<Integer> list= new ArrayList<Integer>(){{
        add(1);
        add(2);
        add(3);
    }};

方法二

Arrays.asList(1,1,2,3,4)

Map的初始化方法

Map<Integer,Integer> map= new HashMap<Integer,Integer>(){{
        put(1,1);
        put(2,2);
        put(3,3);
    }};

注意:在创建时泛型的类型不能省略

注意:此种方法不建议使用,容易造成内存溢出!!!

分类:

技术点:

相关文章:

  • 2021-06-11
  • 2021-05-13
  • 2021-11-24
  • 2022-12-23
  • 2021-05-23
  • 2021-09-03
  • 2022-02-05
  • 2021-08-29
猜你喜欢
  • 2021-10-11
  • 2022-02-28
  • 2021-11-07
  • 2022-12-23
  • 2021-07-29
  • 2022-12-23
相关资源
相似解决方案