ArraysToListGenerics1.htm
Objectives:
  • Type Safe synchronization from Arrays to List<Generics>
  • Example of Arrays.asList(array-object).
 

Edit the code: as shown in the image below

Complete Code:
//Collection_ArrayList1.htm 
import java.io.*;
import java.lang.reflect.*;
import java.util.*;

public class ClassTemplate1 { 

 public ClassTemplate1() {
// TODO Auto-generated constructor stub
str2="encapsulated strictly Private scope"; 
System.out.println(str2);
}

public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
	String[] array1 = {"Jan" ,"Feb", "Mar"}; 
try{
  System.out.println(" Arrays List string objects---"); 
  ArrayList str1 = new ArrayList();
  str1.add("Tom");str1.add("Pan");str1.add("Steve");
  //calling static class directly with class name
  Process.display1(str1); 
 //filling list with array
  //List<String>list = new ArrayList(Arrays.asList(array1)); 
 List<String>list = new ArrayList<String>(Arrays.asList(array1)); 
  System.out.println(list); 

}catch(NumberFormatException e){
//
}
}
}
//Reference super class
class Process{
Process() {} //  constructor

public static void display1(ArrayList<String> str1 ){
for(String stx : str1)
{
System.out.println("\t"+ stx + " array of "+ str1.toString());
}
}
}

}	
Runtime View

<String>