Collections.singleton

论坛 期权论坛 脚本     
匿名技术用户   2021-1-7 07:48   11   0

返回只包含特定对象的集合,集合size为1.

String init[] = { "One", "Two", "Three", "One", "Two", "Three" };

List list1 = new ArrayList(Arrays.asList(init));

List list2 = new ArrayList(Arrays.asList(init));

list1.remove("One");

System.out.println(list1);

// [Two, Three, One, Two, Three]

list2.removeAll(Collections.singleton("One"));

System.out.println(list2);

// [Two, Three, Two, Three]

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP