java list map在初始化的时候添加元素



List<String> list = new ArrayList<String>(){{
  add("First Object");
  add("Second Object");
  add("Third Object");
}};

Map<String, String> map = new HashMap<String, String>(){{
  put("First Key", "First Value");
  put("Second Key", "Second Value");
  put("Third Key", "Third Value");
  put("Fourth Key", "Fourth Value");
}};

 

posted @ 2019-09-05 10:56  护花使者  Views(3450)  Comments(1Edit  收藏  举报