Tag: 集合

我怎样才能初始化我声明它的同一行中的C#列表。 (IEnumerablestring集合示例)

我正在写我的testing代码,我不想写: List<string> nameslist = new List<string>(); nameslist.Add("one"); nameslist.Add("two"); nameslist.Add("three"); 我很想写 List<string> nameslist = new List<string>({"one", "two", "three"}); 然而{“one”,“two”,“three”}不是“IEnumerable string Collection”。 我怎样才能初始化这一行使用IEnumerablestring集合“?

关键值对数据结构的最佳实现?

所以我最近一直在用C#开发,所有的generics集合都让我有点困惑。 假设我想要表示一个数据结构,其中树的头部是一个关键值对,然后在这个关键值对下面有一个可选的列表(但不多于这些关键值)。 这会适合吗? public class TokenTree { public TokenTree() { /* I must admit to not fully understanding this, * I got it from msdn. As far as I can tell, IDictionary is an * interface, and Dictionary is the default implementation of * that interface, right? */ SubPairs = new Dictionary<string, string>(); } public […]

常用util将一个列表分成批处理

我给自己写了一个实用程序,把列表分成一个给定的大小。 我只是想知道,如果已经有任何的Apache公用事业util。 public static <T> List<List<T>> getBatches(List<T> collection,int batchSize){ int i = 0; List<List<T>> batches = new ArrayList<List<T>>(); while(i<collection.size()){ int nextInc = Math.min(collection.size()-i,batchSize); List<T> batch = collection.subList(i,i+nextInc); batches.add(batch); i = i + nextInc; } return batches; } 请让我知道,如果有任何现有的util已经是相同的。

JUnit 4比较集合

你如何简洁地断言collections元素的平等,特别是JUnit 4的Set ?

从java中删除列表中的项目

在循环列表时,我想根据如下条件删除一个列表项 这是给我concurrentModificationexception for(Object a: list){ if(a.getXXX().equalsIgnoreCase("AAA")){ logger.info("this is AAA……..should be removed from the list "); list.remove(a); } } 这应该如何处理

用Java创build空白地图的最佳方法

我需要创build一个空的地图。 if (fileParameters == null) fileParameters = (HashMap<String, String>) Collections.EMPTY_MAP; 问题是上面的代码会产生这样的警告: types安全性:取消选中从映射到HashMap 什么是最好的方式来创build这个空的地图?

那里有没有重复的List实现?

我知道SortedSet ,但在我的情况下,我需要的东西,实现List ,而不是Set 。 那么在API或其他地方是否有实现? 实施自己应该不难,但我想到了为什么不先问这里的人呢?

识别列表中的重复项

我有一个Integertypes的列表,例如: [1, 1, 2, 3, 3, 3] 我想要一个方法来返回所有的重复,例如: [1, 3] 做这个的最好方式是什么?

我可以使用集合初始值设定项与NameValueCollection?

有没有办法使用C#集合初始化语法来初始化NVC: NameValueCollection nvc = new NameValueCollection() { ("a", "1"), ("b", "2") }; 谢谢

将string数组转换为java.util.List

如何将String数组转换为java.util.List ?