【问题标题】:Adding set to iterable list in java [closed]在java中添加集合到可迭代列表[关闭]
【发布时间】:2013-10-28 00:24:13
【问题描述】:

所以我有一些 Set,我想将元素添加到 LinkedList,以便可以迭代它们。我将如何在 java 中执行此操作?

【问题讨论】:

  • 带代码。带代码。或互联网搜索,然后编码。
  • puslic static void main(String[] args)

标签: java set iterable


【解决方案1】:

取自这里的一个问题:Adding items to end of linked list

class Node {
    Object data;
    Node next;
    Node(Object d,Node n) {
        data = d ;
        next = n ;
       }

   public static Node addLast(Node header, Object x) {
       // save the reference to the header so we can return it.
       Node ret = header;
   // check base case, header is null.
   if (header == null) {
       return new Node(x, null);
   }

   // loop until we find the end of the list
   while ((header.next != null)) {
       header = header.next;
   }

   // set the new node to the Object x, next will be null.
   header.next = new Node(x, null);
   return ret;
   }
}

【讨论】:

    猜你喜欢
    • 2021-02-12
    • 2012-07-22
    • 2012-04-02
    • 2011-05-02
    • 2014-09-10
    • 2015-02-07
    • 2021-12-03
    • 2011-11-16
    • 2015-05-16
    相关资源
    最近更新 更多