Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

java list of arrays

import java.util.*;

public class ListofArrays {
	public static void main(String []args)
	{
		List<Integer[]> list;
		list = new ArrayList<Integer[]>();

		// Let us create 2 arrays of type Integer

		Integer [] arr1 = new Integer[5];
		Integer [] arr2 = new Integer[5];
		//arr1 stores numbers from 0 to 4
		//arr2 stores the numbers from 5 to 9
		for(int i=0;i<5;i++)
		{
			arr1[i] = i;
		}
		for(int i=0;i<5;i++)
		{
			arr2[i] = i+5;
		}
		//adding both arrays to list
		list.add(arr1);
		list.add(arr2);
		//print elements of the list
		for(int i=0;i<list.size();i++)
		{
			Integer [] arr = list.get(i);
			for(int j=0;j<arr.length;j++)
			{
				System.out.print(arr[j]+ " ");
			}
			System.out.println();
		}
	}
}
Source by www.delftstack.com #
 
PREVIOUS NEXT
Tagged: #java #list #arrays
ADD COMMENT
Topic
Name
9+2 =