我需要创建一个采用TreeSet或HashSet的Facade.它的构造函数必须如下所示:
CollectionFacadeSet(java.util.Collection<java.lang.String> collection)
Run Code Online (Sandbox Code Playgroud)
我导入java集合并使用此行:
Collections <String> collection = new Collections<>();
Run Code Online (Sandbox Code Playgroud)
但是,java不接受它,我收到一个错误:
- 类型集合不是通用的; 它不能用参数参数化
- 类型集合不是通用的; 它不能用参数<>进行参数化
任何解决方案
谢谢!
我想创建一个链式哈希表.它需要是一个链表的列表,这些结构说我应该这样做:
ArrayList<LinkedList<String>> hashTable
Run Code Online (Sandbox Code Playgroud)
初始化表我使用此代码:
public static ArrayList<LinkedList<String>> createNewTable (){
double tableSize = Math.pow(baseTableSize, initialTableExponent);
for (int i = 0; i < tableSize; i++){
LinkedList<String> row = new LinkedList<String>();
hashTable.add(row);
}
return hashTable;
}
Run Code Online (Sandbox Code Playgroud)
但是,当我在"主"中运行它时,我得到了这个例外:
线程"main"java.lang.NullPointerException中的异常
问题是什么?有没有更好的方法呢?
谢谢!
我需要包装五个类:linkedlist,treeset,hashset和我自己创建的两个类.包装器和我的两个类都在实现相同的接口.这是包装器构造函数:
private Collection <String> collection;
public CollectionFacadeSet(java.util.Collection<java.lang.String> collection){
this.collection = collection;
}
Run Code Online (Sandbox Code Playgroud)
现在,在另一个类中,我想创建一个5单元格数组,每个单元格包含一个不同的集合.这条线还可以:
static CollectionFacadeSet[] setArray = new CollectionFacadeSet[5];
Run Code Online (Sandbox Code Playgroud)
但是,当我创建一个填充单元格的方法时:
private static void initializieArray(){
setArray[0] = CollectionFacadeSet(HashSet<String>);
}
Run Code Online (Sandbox Code Playgroud)
它给我一个错误:
令牌">"上的语法错误,此令牌后预期的表达式
任何想法如何使用不同的设置类型启动每个单元格?
吃了很多.