java链表数组,您可以创建链表的Java中的数组?

这篇博客探讨了在 Java 中是否可以创建链表数组或链表的数组列表。答案是肯定的,Java 允许将任何类型的对象放入数组或列表中,包括链表。示例代码展示了如何创建一个 ArrayList,其元素是 LinkedList 对象,从而实现链表的数组列表。这表明 Java 的灵活性允许开发者根据需求组合不同的数据结构。
摘要由CSDN通过智能技术生成

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.

Thanks in advance.

解决方案

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 array = new ArrayList();

array.add(one);

array.add(two);

array.add(three);

// .. do stuff

}

}

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值