package org.JavaIncloud.java;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import javax.swing.border.Border;
public class ListShowCase
{
public static void main
(String...
JavaInCloud) {
/*create an ArrayList(a class implements List) and assign to a list as we can not create object for List interface*/
List<String> birds = new ArrayList<String>();
//Store some birds name to the collection of bird object(Here String)
birds.add("Penguins");
birds.add("Crows");
birds.add("Sparrows");
birds.add("Dippers");
birds.add("Manakins");
/*print the ArrayList, it'll print the bird name, as internally ArrayList overwrite toString()*/
System.
out.
println("Bird Name>>"+birds
); //output:Dippers:Bird Name>>[Penguins, Crows, Sparrows, Dippers, Manakins]
/*get a specific element using index over get(...) method*/
System.
out.
println(birds.
get(3));//output:Dippers
/*Get an instance of iterator from array list.Iterator is an interface implemented by ArrayList indirectly*/
Iterator<String> iterator = birds.iterator();
/*Retrieve element using Iterator's next() method*/
while (iterator.hasNext())
{
}
//output:Dippers: Penguins,Crows,Sparrows,Dippers,Manakins,
/*similarly you can iterate it using for-each and ListIterator in reverse and forward direction
*ListIterator listIterator = birds.listIterator();*/
}
}
cGFja2FnZSBvcmcuSmF2YUluY2xvdWQuamF2YTsKCmltcG9ydCBqYXZhLnV0aWwuQXJyYXlMaXN0OwppbXBvcnQgamF2YS51dGlsLkl0ZXJhdG9yOwppbXBvcnQgamF2YS51dGlsLkxpc3Q7CmltcG9ydCBqYXZhLnV0aWwuTGlzdEl0ZXJhdG9yOwoKaW1wb3J0IGphdmF4LnN3aW5nLmJvcmRlci5Cb3JkZXI7CgpwdWJsaWMgY2xhc3MgTGlzdFNob3dDYXNlIAp7CglwdWJsaWMgc3RhdGljIHZvaWQgbWFpbihTdHJpbmcuLi5KYXZhSW5DbG91ZCkgCgl7CgkJLypjcmVhdGUgYW4gQXJyYXlMaXN0KGEgY2xhc3MgaW1wbGVtZW50cyBMaXN0KSBhbmQgYXNzaWduIHRvIGEgbGlzdCBhcyB3ZSBjYW4gbm90IGNyZWF0ZSBvYmplY3QgZm9yIExpc3Qga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