Java ArrayList

The java collections framework is made available by the java.util package. Many useful interface, such as Collection, List and Set, are defined in this framework. Many useful classes, such as Collections, LinkedList, HashSet and Treeset are defined in the framework. THE ARRAYLIST CLASS The ArrayList class extends the AbstractList class, which is a predefined class. … Read more…

Java ArrayList toArray

The toArray() method that both array collections implement does this for you. You typically use the method like this: String[] getarray = new String[array1.size()]; getarray = array1.toArray(getarray); The toArray() method here returns an array of type String[] containing all the elements from names in the correct sequence. Program       Program Source import java.util.ArrayList; … Read more…

Java-LinkedList

The LinkedList class implements the List interface. Actuallly, the LinkedList class provides a linked-list data structure. Two important forms of the constructor of this class are as follows: LinkedListList() LinkedList ( Collection c ) When we use the first form of the constructor, an empty linked list will be formed. The second form of the … Read more…

Java LinkedList : get()

The get() method Returns the element at the specified position in linkedlist. Program       Program Source import java.util.LinkedList; public class Javaapp { public static void main(String[] args) { LinkedList list1 = new LinkedList(); list1.add(“AAAA”); list1.add(“BBBB”); list1.add(“CCCC”); list1.add(“DDDD”); list1.add(“EEEE”); list1.add(“FFFF”); for(int i=0;i < list1.size();i++) { System.out.println(list1.get(i)); } } }

Iterator : hasNext() and next()

Each of the collection classes provides an iterator( ) method that returns an iterator to the start of the collection. By using this iterator object, you can access each element in the collection, one element at a time. In general, to use an iterator to cycle through the contents of a collection, follow these steps: … Read more…

ListIterator : hasNext(), next(), hasPrevious() and previous()

ListIterator is used just like Iterator. For collections that implement List, you can also obtain an iterator by calling listIterator(). A list iterator gives you the ability to access the collection in either the forword or backword direction and lets you modify an element. The hasPrevious( ) method returns true if there is a previous … Read more…