Collection_List_ArrayList1
 

Printing methods:

Complete Code:

//
import java.io.*;
import java.lang.reflect.*;
import java.util.*;

public class ClassTemplate1 {

public String str1; private String str2; 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 = {"ABC" ,"ACD", "AEF", "AFG","ADE"};
String[] array2 = {"Peter" ,"Sam", "Adam", "Julia","Nat"};
try{
//simple_list2
List<String> list1 = new ArrayList<String>();
List<String> list2= new ArrayList<String>(Arrays.asList(array2));
for(String str1: array1)// populating list with array
{
list1.add(str1);
}
System.out.println("Printing list1.add(str1):: List<String> str1");
Process.display(list1);
System.out.println();
System.out.println("Printing list1.add(str1):Collection<String> str1");
Process.display2(list1);
System.out.println();
System.out.println("Printing (Arrays.asList(array2):Collection<String> str1");
Process.display2(list2);


System.out.println();
}catch(NumberFormatException e){
//
}
}
}
class Process{

Process(){}
public static void display(List<String> str1){
for (Object obj1 :str1)
System.out.print(" " +obj1);
}
public static void display2(Collection<String> str1){
//ListIterator<Object> iter = str1.listIterator();
for (Object obj1 :str1)
System.out.print(" " +obj1);
}
}
 

Runtime Views: