CORE API / CATATAN</>↗Core API15 Nov 2009
To reverse the order of LinkedList elements we can use the reverse(List<?> list) static method of java.util.Collections class. Here is the example: package org.kodejava.util; import java.util.LinkedList; import java.util.Collections; public class LinkedListReverseOrder { public static void main(String[] args) { LinkedList<String> grades = new LinkedList<>(); grades.add("A"); grades.add("B"); grades.add("C"); grades.add("D"); grades.add("E"); grades.add("F"); System.out.printl...
CORE API / CATATAN</>↗Core API11 Nov 2009
This program shows you how to use the remove(int index) method of LinkedList class to remove an item at specified index from linked list object. package org.kodejava.util; import java.util.LinkedList; public class LinkedListRemove { public static void main(String[] args) { LinkedList<String> names = new LinkedList<>(); names.add("Alice"); names.add("Bob"); names.add("Carol"); names.add("Mallory"); System.out.println("Original values are:"); System.out.println("===============...
CORE API / CATATAN</>↗Core API07 Nov 2009
To insert an item at any position into a linked list object we can use the add(int index, Object o) method. This method takes the index to where the new object to be inserted and the object to be inserted itself. package org.kodejava.util; import java.util.LinkedList; public class LinkedListAddDemo { public static void main(String[] args) { […]
CORE API / CATATAN</>↗Core API03 Nov 2009
To add an item before the first item in the linked list we use the LinkedList.addFisrt() method and to add an items after the last item in the linked list we use the LinkedList.addLast() method. package org.kodejava.util; import java.util.LinkedList; public class LinkedListAddItems { public static void main(String[] args) { LinkedList<String> grades = new LinkedList<>(); grades.add("B"); […]
CORE API / CATATAN</>↗Core API30 Okt 2009
To remove the first or the last elements from the linked list we can use the removeFirst() and removeLast() methods provided by the LinkedList class. package org.kodejava.util; import java.util.LinkedList; public class LinkedListRemoveItems { public static void main(String[] args) { LinkedList<String> grades = new LinkedList<>(); grades.add("A"); grades.add("B"); grades.add("C"); grades.add("D"); grades.add("E"); grades.add("F"); System.out.println("Original values are:"); Sy...
CORE API / CATATAN</>↗Core API26 Okt 2009
The example show you how to retrieve particular object from LinkedList using the indexOf() method. package org.kodejava.util; import java.util.List; import java.util.LinkedList; public class LinkedListIndexOf { public static void main(String[] args) { List<String> names = new LinkedList<>(); names.add("Alice"); names.add("Bob"); names.add("Carol"); names.add("Mallory"); // Search for Carol using the indexOf method. This method // returns the index of […]