- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create an array of linked lists in java?
A linked list is a sequence of data structures, which are connected together via links.
To create an array of linked lists, create required linked lists and, create an array of objects with them.
Example
import java.util.LinkedList; public class ArrayOfLinkedList { public static void main(String args[]) { LinkedList list1 = new LinkedList(); list1.add("JavaFX"); list1.add("Hbase"); LinkedList list2 = new LinkedList(); list2.add("OpenCV"); list2.add("Mahout"); LinkedList list3 = new LinkedList(); list3.add("WebGL"); list3.add("CoffeeScript"); Object[] obj = {list1, list2, list3}; for (int i=0; i<obj.length; i++) { System.out.println(obj[i].toString()); } } }
Output
[JavaFX, Hbase] [OpenCV, Mahout] [WebGL, CoffeeScript]
You can also create Array list of linked lists as –
Example
import java.util.ArrayList; import java.util.LinkedList; public class ArrayOfLinkedList { public static void main(String args[]) { LinkedList list1 = new LinkedList(); list1.add("JavaFX"); list1.add("Hbase"); LinkedList list2 = new LinkedList(); list2.add("OpenCV"); list2.add("Mahout"); LinkedList list3 = new LinkedList(); list3.add("WebGL"); list3.add("CoffeeScript"); ArrayList <LinkedList> aList = new ArrayList<LinkedList>(); aList.add(list1); aList.add(list2); aList.add(list1); System.out.println(aList); } }
Output
[[JavaFX, Hbase], [OpenCV, Mahout], [JavaFX, Hbase]]
- Related Articles
- How to create an Array in Java?
- How to create an array of Object in Java
- Merge K sorted linked lists in Java
- How to create an ArrayList from an Array in Java?
- Find the Intersection Point of Two Linked Lists in Java
- How to create LabelValue Tuple from an array in Java
- How to create array of strings in Java?
- Intersection of Two Linked Lists in Python
- Intersection of Two Linked Lists in C++
- Doubly linked lists in Javascript
- Circular linked lists in Javascript
- How to create a constructor reference for an array in Java?
- How to declare, create, initialize and access an array in Java?
- How to create a vector of lists in R?
- How to create Definition Lists in HTML5?

Advertisements