本文介绍了您可以创建链表的Java中的数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能创建链表的数组?或链表的ArrayList?我一直在寻找无处不在,似乎变得矛盾的答案。我已经看到了不的答案,那说明它不能这样做,因为你不能让事情可以解除引用数组。我见过的状态是可以做到的回答是,他们结束。

Is it possible to create an array of linked lists? Or an arraylist of linked lists? I've been searching everywhere and seem to be getting contradicting answers. I've seen "no" answers that state that it can't be done because you can't make an array of things that can be dereferenced. I've seen "yes" answers that state it can be done and they end there.

先谢谢了。

推荐答案

如果我理解你的权利,你basicly想使一个二维数组,但随着下半年是一个链表。

If I understand you right, you basicly want to make a 2D Array, but with the second half being a linked list.

import java.util.ArrayList;
import java.util.LinkedList;

public class Test
{
    public static void main(String[] args)
    {
        LinkedList one = new LinkedList();
        LinkedList two = new LinkedList();
        LinkedList three = new LinkedList();

        ArrayList<LinkedList> array = new ArrayList<LinkedList>();

        array.add(one);
        array.add(two);
        array.add(three);

        // .. do stuff
    }
}

Java不关心什么在数组或列表中的对象,所以没有什么反对把在另一个数组或列表。

Java doesn't care what the Objects in Arrays or Lists are, so there's nothing against putting another Array or List in.

这篇关于您可以创建链表的Java中的数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 19:06