Monday, 16 January 2017

LinkedList : GetMethod





import java.util.LinkedList;

public class GetMethod {

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");

for (int i = 0; i<ll1.size(); i++)
{
System.out.print(ll1.get(i)+", ");
}

System.out.print("\n Get First element of list  : ");
System.out.print(ll1.getFirst());

System.out.print("\n Get Last element of list  : ");
System.out.print(ll1.getLast());
}
}

No comments:

Post a Comment