Monday, 16 January 2017

LinkedList : IndexMethod





import java.util.LinkedList;

public class IndexMethod {

public static void main(String[] args) {
// TODO Auto-generated method stub


LinkedList<String> ll1 = new LinkedList<>();

ll1.add("One");
ll1.add("Two");
ll1.add("Three");
ll1.add("Four");
ll1.add("Five");
ll1.add("Two");
ll1.add("Three");
ll1.add("Four");

System.out.print("Full-List : "+ll1);

System.out.print("\n Get index of 'Five' in list  : ");
System.out.print(ll1.indexOf("Five"));

System.out.print("\n Get Last index of 'Three' in list  : ");
System.out.print(ll1.lastIndexOf("Three"));

}
}

No comments:

Post a Comment