CORE API / NOTES</>↗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 / NOTES</>↗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 / NOTES</>↗Core API30 Oct 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 / NOTES</>↗Core API26 Oct 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 […]
CORE API / NOTES</>↗Core API22 Oct 2009
This example show you how to use the ListIterator interface to iterate elements of a LinkedList. package org.kodejava.util; import java.util.List; import java.util.LinkedList; import java.util.ListIterator; public class LinkedListListIterator { public static void main(String[] args) { List<String> grades = new LinkedList<>(); grades.add("A"); grades.add("B"); grades.add("C"); grades.add("D"); grades.add("E"); // Retrieves object from LinkedList using the ListIterator // inter...
CORE API / NOTES</>↗Core API18 Oct 2009
This example show you how to use the Iterator interface to iterate elements of a LinkedList. package org.kodejava.util; import java.util.List; import java.util.LinkedList; import java.util.Iterator; public class LinkedListIterator { public static void main(String[] args) { List<String> grades = new LinkedList<>(); grades.add("A"); grades.add("B"); grades.add("C"); grades.add("D"); grades.add("E"); // Iterates elements in LinkedList using Iterator. Iterator<String> iterator =...