List<Object> nullList = Collections.singletonList(null);核心特点不可变性:返回的列表是只读的,调用 add()、remove()、clear() 等修改方法会抛出 UnsupportedOperationException。List<String> list = Collections.singletonList("T
抱起亚轩找小葵
2026-01-15 23:08
[代码比较] CollectionssingletonList 与 Listof
1. Collections.singletonList:创建不可变单元素列表功能:返回一个仅包含单个元素的不可变List 视图,线程安全且访问高效。示例:String name = "Alice";List<String> names = Collections.singletonList(name);特点:不可修改性:不支持add、remove、clear 等操作,调用会抛出UnsupportedOperat
大圣杰锅是
2026-01-15 23:08
easyexcel动态表头多级并合并单元格
5. 代码示例对比// 使用 Collections.singletonListList<Address> addresses1 = Collections.singletonList( new Address("742 Evergreen Terrace", "Springfield", "New York", "13468", "US"));// 使用 List.ofList<Address> addresses2 =...
小韩在追星
2026-01-15 23:08
easyexcel 表头动态赋值
List<List<String>> head = new ArrayList<>();// 第一列:两级表头("主标题1"→"子标题1")head.add(Arrays.asList("主标题1", "子标题1"));// 第二列:单级表头("主标题2")head.add(Collections.singletonList("主标题2...
小韩在追星
2026-01-15 23:08
easyExcel生成动态表头
List<List<String>> head = new ArrayList<>();head.add(Collections.singletonList("动态列1"));head.add(Collections.singletonList("动态列2"));EasyExcel.write("output.xlsx") .head(head) // 动态传入表头 .sheet("动态Sheet") .doWri...