Array and List in Java
Today we will learn how to create a Java array of ArrayList. We will also learn how to create an ArrayList of array elements. Java Array of ArrayListCreating array of list in java is not complex. Below is a simple program showing java Array of ArrayList example. Notice that we cant use generics while creating the array because java doesnt support generic array. So if we try to use below code, it will produce compile time error as Cannot create a generic array of List Java ArrayList of ArrayWe can also create an array whose elements are a list. Below is a simple example showing how to create a list of array elements in java. import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class JavaArrayListOfStringArray { public static void main(String[] args) { // List of String arrays ListJava ArrayList of Object ArrayIf you are not sure about the type of objects in the array or you want to create an ArrayList of arrays that can hold multiple types, then you can create an ArrayList of an object array. Below is a simple example showing how to create ArrayList of object arrays in java. import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class JavaArrayListOfObjectArray { public static void main(String[] args) { // list of Object arrays to hold different types of array List |