How to add strings to list and print the elements of the list in Java

1 Answer

0 votes
package javaapplication1;

import java.util.List;
import java.util.ArrayList;

public class Example {
    public static void main(String[] args) {
             
        List list = new ArrayList();
        
        list.add("Java");
        list.add("Programming");
	
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }
    }
}


/*
run:
 
Java
Programming
 
*/

 



answered Jan 16, 2016 by avibootz
edited Jan 16, 2016 by avibootz
...