This Java program creates an ArrayList of String type named list_Str and adds seven elements to it using the add() method of ArrayList. The elements added to the list are "Apple", "Banana", "Cherry", "Pineapple", "Guava", "Papaya" and "Plum". Finally, the program prints the elements of the list using the println() method of System.out object.
import java.util.*; class Add_Elements { public static void main(String[] args) { List<String> list_Str = new ArrayList<String>(); list_Str.add("Apple"); list_Str.add("Banana"); list_Str.add("Cherry"); list_Str.add("Pineapple"); list_Str.add("Guava"); list_Str.add("Papaya"); list_Str.add("Plum"); System.out.println(list_Str); } }
[Apple, Banana, Cherry, Pineapple, Guava, Papaya, Plum]
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions