Store User-Defined Objects in Collections

The power of collections is that they can store any type of object, including objects of classes that you create. For example, consider the following example that uses a LinkedList to store¬†Store User-Defined Objects. Program Program Source import java.util.LinkedList; class StudentData { String name; int age; StudentData(String na, int ag) { name = na; age … 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)); } } }

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…