import static java.lang.System.out;
import java.util.Arrays;
import java.util.List;
class ArrayToList
{
static public void main(String...alt)
{
String[] s={"b","z","c","a","k"};
for(String x:s)
out.print(x+" ");
List l=Arrays.asList(s);
/* It doesn't create an indepdent List object but it points to the same object and just we are viewing exiting array in List Form. We cannot perform any manipulation through which can be effect on size of array(add or remove) otherwise we will get UnsupportedOperationException*/
out.println("\n"+l);
}
}
import java.util.Arrays;
import java.util.List;
class ArrayToList
{
static public void main(String...alt)
{
String[] s={"b","z","c","a","k"};
for(String x:s)
out.print(x+" ");
List l=Arrays.asList(s);
/* It doesn't create an indepdent List object but it points to the same object and just we are viewing exiting array in List Form. We cannot perform any manipulation through which can be effect on size of array(add or remove) otherwise we will get UnsupportedOperationException*/
out.println("\n"+l);
}
}
0 Comment to " Java Program to convert Array to List."
Post a Comment