Java – List Example

List example give a method, how to use List in java:

  1. Code:
    import java.util.Iterator;
    import java.util.List;
    import java.util.ArrayList;
    
    public class ListExample {
    
        public static void main(String[] args) {
    
            // List Example implement with ArrayList
            List<String> ls=new ArrayList<String>();
    
            ls.add("one");
            ls.add("Three");
            ls.add("two");
            ls.add("four");
    
            Iterator it=ls.iterator();
    
            while(it.hasNext())
            {
              String value=(String)it.next();
    
              System.out.println("Value :"+value);
            }
        }
    }
  2. Output:
    List Value :One
    List Value :Three
    List Value :two
    List Value :four

Reference Link: http://www.easywayserver.com/blog/java-list-example/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s