创建空List:
Collections.emptyList();
创建单个元素的List:
Collections.singletonList("item");
但是需要注意,上面两种创建方式创建出来的List都是不可变List,创建可变List的快捷方式可以使用google工具包中提供的方法:
import com.google.common.collect.Lists; ArrayList<String> list = Lists.newArrayList("12", "23"); list.add("344"); System.out.println(list);//[12, 23, 344]
方式一:
ImmutableMap<String, String> of = ImmutableMap.of("key1", "value1", "key2", "value2", "key3", "value3");
方式二:
Map<String, String> stringStringMap = ImmutableMap.<String,String>builder() .put("page","page/page/index") .put("templateId","") .put("formId","") .build();
优雅,永不过时