List is interface and ArrayList is class which implements List Interface.
To add elements to List, add() method is used.
List provied toArray metiond which is used to convert basically Collection to Array using Java
List.toArray(new String[0]):
Java Program to convert List to Array :
Output:
Apple Juice
Pinaple Juice
Watermalones Juice
To add elements to List, add() method is used.
List provied toArray metiond which is used to convert basically Collection to Array using Java
List.toArray(new String[0]):
Java Program to convert List to Array :
ListlstFruit = new ArrayList (); lstFruit.add("Apple Juice "); lstFruit.add("Pinaple Juice"); lstFruit.add("Watermalones Juice"); String[] arrayFruits = lstFruit.toArray(new String[0]); for(int i = 0; i < arrayFruits.length; ++i){ System.out.println(arrayFruits[i]); }
Output:
Apple Juice
Pinaple Juice
Watermalones Juice
No comments:
Post a Comment