How to create a linked list in java?
This question already has an answer here:
这就是列表中的指针在内部看起来如何add
其实际add
到列表中,您需要这样做:
List<String> s = new LinkedList<>();
s.add("a");
s.add("b");
s.add("c");
s.add("d");
Take a look at this answer.
LinkedList<String> list = new LinkedList<>();
list.add("a");
list.add("b");
list.add("c");
list.add("d");
If you really want it on one line:
LinkedList<String> list = new LinkedList<>(Arrays.asList("a","b","c","d"));
Though that does have a performance overhead.
你可以这样做:
LinkedList<String> linkedList = new LinkedList<String>();
linkedList.add("a");
linkedList.add("b");
linkedList.add("c");
linkedList.add("d");
链接地址: http://www.djcxy.com/p/27716.html
上一篇: 单身收集到多个对象收集
下一篇: 如何在java中创建链表?