如何在java中从链表中找到中间值或节点?

我在链接list.how中有50个值来查找链表的中间值或节点?

List list = new LinkedList(); for (int i = 0; i < 50; i++) { list.add(String.valueOf(i)); } int size = list.size(); int middle = (size / 2); System.out.println(list.get(middle).toString());... 

我得到了这样的答案….但我的团队负责人说要以另一种方式找到答案? 有没有其他内置的方法来迭代链表?我试过……但我得到任何内置的方法来查找中间值…或者你可以任何人建议另一个逻辑来找到中间节点的值林克名单?

谢谢…….

获得对同一列表的2个引用。

 In a single loop: Advance the 1st list 2 nodes at a time. Advance the 2nd list 1 node at a time. Loop until the 1st loop reaches the end. 
 List list = new LinkedList(); for (int i = 0; i < 50; i++) { list.add(String.valueOf(i)); } int end = list.size() - 1; int start = 0; while (start > end) { start++; end--; } if(start == end) //The arrays length is an odd number and you found the middle return start; else //The arrays length is an even number and there really isn't a middle //Do something else here because you have an even number 

也许你的团队负责人建议你使用ArrayList而不是LinkedList。

 List list = new ArrayList(50);