Add value to the first position in a linked list
import java.util.LinkedList;
public class Main {
public static void main(String[] a) {
LinkedList<String> officers = new LinkedList<String>();
officers.addFirst("B");
officers.addFirst("B");
officers.addFirst("H");
officers.addFirst("P");
officers.addFirst("M");
for (String s : officers)
System.out.println(s);
}
}
Home
Java Book
Runnable examples
Java Book
Runnable examples
Collection LinkedList:
- Add value to the first position in a linked list
- Convert a LinkedList to ArrayList
- Remove first and last elements of LinkedList Java example