The purpose of this tutorial is to give you an overview of the Java Collection classes. All the topics are published with examples and source codes which helps you to understand in effective way.
The Java language supports arrays to store several objects. An array is initialized with a predefined size during instantiation. To support more flexible data structures the core Java library provides the collection framework.
A collection is a data structure which contains and processes a set of data. The data stored in the collection is encapsulated and the access to the data is only possible via predefined methods.
Collections Framework hierarchy:
List is an ordered collection of objects in which duplicate values can be stored. Since List preserves the insertion order it allows positional access and insertion of elements. List Interface is implemented by ArrayList, LinkedList, Vector and Stack classes.
1. ArrayList : Introduction to ArrayList
2. ArrayList : How to initialize an ArrayList
3. ArrayList : How to loop ArrayList
4. ArrayList : How to find length of ArrayList
5. ArrayList : How to sort ArrayList
6. ArrayList : How to sort ArrayList in descending order
7. ArrayList : How to shuffle elements in ArrayList
8. ArrayList : ArrayList add() Method Example
9. ArrayList : Add element at particular index of ArrayList
10. ArrayList : ArrayList addAll() Method example
11. ArrayList : Insert all the collection elements to the specified position in ArrayList
12. ArrayList : Remove element from the specified index in ArrayList
13. ArrayList : Remove specified element from ArrayList
14. ArrayList : How to get sublist of an ArrayList
15. ArrayList : How to Get the index of last occurrence of the element in the ArrayList
16. ArrayList : How to Get the index of first occurrence of the element in the ArrayList
17. ArrayList : How to get an element from ArrayList
18. ArrayList : How to Check whether element exists in ArrayList
19. ArrayList : How to compare two ArrayList in Java
20. ArrayList : How to swap two elements in an ArrayList
21. ArrayList : How to Check whether ArrayList is empty or not
22. ArrayList : How to Trim the Size of ArrayList
23. ArrayList : How to Replace the value of existing element in ArrayList
24. ArrayList : How to empty an ArrayList in Java
25. ArrayList : How to clone an ArrayList to another ArrayList
26. ArrayList : How to join two ArrayLists
27. ArrayList : Java toString Method
28. ArrayList : How to reverse ArrayList content
29. ArrayList : How to Sort ArrayList of Objects using Comparable and Comparator
30. ArrayList : How to convert ArrayList to string array in java
31. ArrayList : How to convert an array to ArrayList in java
LinkedList is a doubly-linked list implementation of the List and Deque interfaces. LinkedList allows for constant-time insertions or removals using iterators, but only sequential access of elements. In other words, LinkedList can be searched forward and backward but the time it takes to traverse the list is directly proportional to the size of the list.
1. LinkedList : Basic LinkedList Operations
2. LinkedList : How to read all elements in LinkedList
3. LinkedList : How to Add element at specific index in LinkedList
4. LinkedList : How to add element at First position in LinkedList
5. LinkedList : How to add element at Last position in LinkedList
6. LinkedList : How to remove elements from LinkedList
7. LinkedList : How to delete all elements from my LinkedList
8. LinkedList : How to add all elements of a list to LinkedList
9. LinkedList : How to read first element from LinkedList
10. LinkedList : How to read last element from LinkedList
11. LinkedList : How to Search elements in LinkedList
12. LinkedList : How to get sub list from LinkedList
13. LinkedList : LinkedList Iterator and ListIterator Example
14. LinkedList : How to Iterate a LinkedList in reverse sequential order
Vector implements List Interface. Like ArrayList it also maintains insertion order but it is rarely used in non-thread environment as it is synchronized and due to which it gives poor performance in searching, adding, delete and update of its elements.
1.Vector : BASIC VECTOR OPERATIONS
2.Vector : HOW TO READ ALL ELEMENTS IN VECTOR BY USING ITERATOR?
3.Vector : HOW TO FIND DOES VECTOR CONTAINS ALL LIST ELEMENTS OR NOT?
4.Vector : HOW TO GET SUB LIST FROM VECTOR?
5.Vector : HOW TO COPY OR CLONE A VECTOR?
6.Vector : HOW TO ADD ALL ELEMENTS OF A LIST TO VECTOR?
7.Vector : HOW TO REMOVE ALL ELEMENTS FROM VECTOR?
8.Vector : HOW TO COPY VECTOR TO ARRAY?
9.Vector : HOW TO READ ALL ELEMENTS IN VECTOR BY USING ENUMERATION?
Set is a collection that cannot contain duplicate elements. Set interface doesn’t allow random-access to an element in the Collection. You can use iterator or foreach loop to traverse the elements of a Set.
The Java platform contains three general-purpose Set implementations: HashSet, TreeSet, and LinkedHashSet.
1.HashSet : HashSet Class in Java
2.HashSet : How to Delete all the elements from HashSet ?
3.HashSet : How to Iterate over a Set or HashSet ?
4.HashSet : How to copy Set content to another HashSet ?
5.HashSet : How to Convert a HashSet to an Array ?
6.HashSet : How to Convert a HashSet to a List Or ArrayList ?
7.HashSet : How to copy all elements from HashSet to an array ?
8.HashSet : How to compare two sets and retain elements which are same on both sets ?
9.HashSet : How to eliminate duplicate user defined objects from HashSet ?
10.HashSet : How to find user defined objects from HashSet ?
11.HashSet : How to delete user defined objects from HashSet ?
Java Map is an object that maps keys to values. A map cannot contain duplicate keys: Each key can map to at most one value.
The basic operations of Map are put, get, containsKey, containsValue, size, and isEmpty.
The Java platform contains three general-purpose Map implementations: HashMap, TreeMap, and LinkedHashMap.
Both Iterator and ListIterator are used to iterate through elements of a collection class. Using Iterator we can traverse in one direction (forward) while using ListIterator we can traverse the collection class on both the directions (backward and forward).
- Java Iterator with examples
- Difference between Iterator and Enumeration
- Java ListIterator with examples
- Methods of ListIterator
547total visits,1visits today