[Go to site: main page, start]

0% found this document useful (0 votes)
4 views52 pages

Adv. Java Module-1 Notes

Module 1 of the Advanced Java course focuses on the Collections Framework in Java, which provides dynamic data structures such as ArrayList, LinkedList, and HashSet. It introduces key interfaces like Collection, List, Set, and their implementations, emphasizing the importance of a unified architecture for data manipulation. The module also covers iterators for accessing collections and demonstrates the use of user-defined classes within collections.

Uploaded by

hemabhooshithal
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views52 pages

Adv. Java Module-1 Notes

Module 1 of the Advanced Java course focuses on the Collections Framework in Java, which provides dynamic data structures such as ArrayList, LinkedList, and HashSet. It introduces key interfaces like Collection, List, Set, and their implementations, emphasizing the importance of a unified architecture for data manipulation. The module also covers iterators for accessing collections and demonstrates the use of user-defined classes within collections.

Uploaded by

hemabhooshithal
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Module 1

Collections Framework in Java

Course Instructor: [Link] R


Course Code: BCS613D – Professional Elective
Credits: 3
Scheme: 2022 - VTU

Get more study materials and resources at VTUCrack


Date: 12/2/2025

Advanced Java _BCS613D

Module 1

Collections Framework

1. Introduction to the Collection Framework

Although we can use an array as a container to store a group of elements of the same type (primitives
or objects). The array, however, does not support so-called dynamic allocation - it has a fixed
length which cannot be changed o nce allocated. Furthermore, array is a simple linear structure. Many
applications may require more complex data structure such as linked list, stack, hash table, set, or tree.

In Java, dynamically allocated data structures (such


as ArrayList, LinkedList, Vector, Stack, HashSet, HashMap, Hashtable) are supported in a unified
architecture called the Collection Framework, which mandates the common behaviors of all the
classes.

A collection, as its name implied, is simply a container object that holds a collection of objects. Each
item in a collection is called an element. A framework, by definition, is a set of interfaces that force
you to adopt some design practices. A well-designed framework can improve your productivity and
provide ease of maintenance.

The collection framework provides a unified interface to store, retrieve and manip ulate the elements of
a collection, regardless of the underlying actual implementation. This allows the programmers to
program at the interface specification, instead of the actual implementation.
The Java Collection Framework package ([Link]) contains:

1. A set of interfaces,

2. Implementation classes, and

3. Algorithms (such as sorting and searching).

(Similar Collection Framework is the C++ Standard Template Library (STL)).

Get more study materials and resources at VTUCrack


Date: 12/2/2025

Prior to JDK 1.2, Java's data structures consist of array, Vector, and Hashtable that were designed in a
non-unified way with inconsistent public interfaces. JDK 1.2 introduced the unified collection
framework, and retrofits the legacy classes (Vector and Hashtable) to conform to this
unified collection framework.
JDK 5 introduced Generics (which supports passing of types), and many related features (such as
auto-boxing/auto-unboxing and for-each loop). The collection framework is retrofitted to support
generics and takes full advantages of these new features.

To understand this chapter, you have to be familiar with:

 Interfaces, abstract methods and their implementations.

 Inheritance and Polymorphism, especially the upcasting and downcasting operations. See
"Inheritance, Substitution, Polymorphism and Type Casting" for a quick summary.

The Collection Interfaces

The Collection interface in Java is a core member of the Java Collections Framework located in
the [Link] package. It is one of the root interfaces of the Java Collection Hierarchy.
The Collection interface is not directly implemented by any class. Instead, it is implemented
indirectly through its sub-interfaces like List, Queue, and Set.

For Example, the ArrayList class implements the List interface, a sub-interface of the Collection
interface.

The Collection interface is the foundation upon which the Collections Framework is built because it
must be implemented by any class that defines a collection. Collection is a generic interface that has
this declaration: interface Collection<E>

Here, E specifies the type of objects that the collection will hold. Collection extends the Iterable
interface.

Get more study materials and resources at VTUCrack


Date: 12/2/2025

The List Interface

The List interface extends Collection and declares the behavior of a collection that stores a sequence
of elements. Elements can be inserted or accessed by their position in the list, using a zero-based
index. A list may contain duplicate elements. List is a generic interface that has this declaration:
interface List<E>
Here, E specifies the type of objects that the list will hold.

The Set Interface


The Set interface defines a set. It extends Collection and declares the behavior of a collection that does
not allow duplicate elements. Therefore, the add( ) method returns false if an attempt is made to add
duplicate elements to a set. It does not define any additional methods of its own. Set is a generic
interface that has this declaration:
interface Set<E>
Here, E specifies the type of objects that the set will hold.

The SortedSet Interface

The SortedSet interface extends Set and declares the behavior of a set sorted in ascending order.
SortedSet is a generic interface that has this declaration:

interface SortedSet<E>

Here, E specifies the type of objects that the set will hold.

Get more study materials and resources at VTUCrack


Date: 12/2/2025

The NavigableSet Interface

The NavigableSet interface was added by Java SE 6. It extends SortedSet and declares the behavior of
a collection that supports the retrieval of elements based on the closest match to a given value or
values. NavigableSet is a generic interface that has this declaration:

interface NavigableSet<E>

Here, E specifies the type of objects that the set will hold.

Get more study materials and resources at VTUCrack


Date: 12/2/2025

The Queue Interface

The Queue interface extends Collection and declares the behavior of a queue, which is often a first-in,
first-out list. However, there are types of queues in which the ordering is based upon other criteria.
Queue is a generic interface that has this declaration:

interface Queue<E>

The Deque Interface

The Deque interface was added by Java SE 6. It extends Queue and declares the behavior of a double-
ended queue. Double-ended queues can function as standard, first-in, first-out queues or as last-in,
first-out stacks. Deque is a generic interface that has this declaration:

interface Deque<E>

Here, E specifies the type of objects that the deque will hold.

Get more study materials and resources at VTUCrack


Date: 12/2/2025

The Collection Classes

The ArrayList Class

The ArrayList class extends AbstractList and implements the List interface. ArrayList is a generic class
that has this declaration:

class ArrayList<E>

Here, E specifies the type of objects that the list will hold.

ArrayList has the constructors shown here:

 ArrayList( )
 ArrayList(Collection c)
 ArrayList(int capacity)

The following program shows a simple use of ArrayList. An array list is created for objects of type
String, and then several strings are added to it.

// Demonstrate ArrayList.

import [Link].*;

class ArrayListDemo {

public static void main(String args[]) {

// Create an array list.

ArrayList<String> al = new ArrayList<String>();

[Link]("Initial size of al: " + [Link]());

Get more study materials and resources at VTUCrack


Date: 12/2/2025

// Add elements to the array list.

[Link]("C");

[Link]("A");

[Link]("E");

[Link]("B");

[Link]("D");

[Link]("F");

[Link](1, "A2");

[Link]("Size of al after additions: " + [Link]());

// Display the array list.

[Link]("Contents of al: " + al);

// Remove elements from the array list.

[Link]("F");

[Link](2);

[Link]("Size of al after deletions: " + [Link]());

[Link]("Contents of al: " + al);

The HashSet Class

HashSet extends AbstractSet and implements the Set interface. It creates a collection that uses a hash
table for storage. HashSet is a generic class that has this declaration:

class HashSet<E>

Here, E specifies the type of objects that the set will hold.

The following constructors are defined:

 HashSet( )

Get more study materials and resources at VTUCrack


Date: 12/2/2025

 HashSet(Collection c)
 HashSet(int capacity)
 HashSet(int capacity, float fillRatio)

Here is an example that demonstrates HashSet:

// Demonstrate HashSet.

import [Link].*;

class HashSetDemo {

public static void main(String args[]) {

// Create a hash set.

HashSet<String> hs = new HashSet<String>();

// Add elements to the hash set.

[Link]("B");

[Link]("A");

[Link]("D");

[Link]("E");

[Link]("C");

[Link]("F");

[Link](hs);

The LinkedHashSet Class

The LinkedHashSet class extends HashSet and adds no members of its own. It is a generic class that
has this declaration:

class LinkedHashSet <E>

Get more study materials and resources at VTUCrack


Date: 12/2/2025

Here, E specifies the type of objects that the set will hold. Its constructors parallel those in HashSet.

The TreeSet Class

TreeSet extends AbstractSet and implements the NavigableSet interface. It creates a collection that
uses a tree for storage. Objects are stored in sorted, ascending order. Access and retrieval times are
quite fast, which makes TreeSet an excellent choice when storing large amounts of sorted information
that must be found quickly. TreeSet is a generic class that has this declaration:

class TreeSet<E>

Here, E specifies the type of objects that the set will hold.

TreeSet has the following constructors:

 TreeSet( )
 TreeSet(Collection c)
 TreeSet(Comparator comp)
 TreeSet(SortedSet ss)

Here is an example that demonstrates a TreeSet:

// Demonstrate TreeSet.

import [Link].*;

class TreeSetDemo {

public static void main(String args[]) {

// Create a tree set.

TreeSet<String> ts = new TreeSet<String>();

// Add elements to the tree set.

[Link]("C");

[Link]("A");

[Link]("B");

[Link]("E");

[Link]("F");

Get more study materials and resources at VTUCrack


Date: 12/2/2025

[Link]("D");

[Link](ts);

}}

The PriorityQueue Class

PriorityQueue extends AbstractQueue and implements the Queue interface. It creates a queue that is
prioritized based on the queue’s comparator. PriorityQueue is a generic class that has this declaration:

class PriorityQueue<E>

Here, E specifies the type of objects stored in the queue. PriorityQueues are dynamic, growing as
necessary.

PriorityQueue defines the six constructors shown here:

 PriorityQueue( )
 PriorityQueue(int capacity)
 PriorityQueue(int capacity, Comparator<? super E> comp)
 PriorityQueue(Collection<? extends E> c)
 PriorityQueue(PriorityQueue<? extends E> c)
 PriorityQueue(SortedSet<? extends E> c)

The ArrayDeque Class

Java SE 6 added the ArrayDeque class, which extends AbstractCollection and implements the Deque
interface. It adds no methods of its own. ArrayDeque creates a dynamic array and has no capacity
restrictions. (The Deque interface supports implementations that restrict capacity, but does not require
such restrictions.) ArrayDeque is a generic class that has this declaration:

class ArrayDeque<E>

Here, E specifies the type of objects stored in the collection.

ArrayDeque defines the following constructors:

 ArrayDeque( )
 ArrayDeque(int size)
 ArrayDeque(Collection<? extends E> c)

The following program demonstrates ArrayDeque by using it to create a stack:

// Demonstrate ArrayDeque.

import [Link].*;

class ArrayDequeDemo {

Get more study materials and resources at VTUCrack


Date: 12/2/2025

public static void main(String args[]) {

// Create a tree set.

ArrayDeque<String> adq = new ArrayDeque<String>();

// Use an ArrayDeque like a stack.

[Link]("A");

[Link]("B");

[Link]("D");

[Link]("E");

[Link]("F");

[Link]("Popping the stack: ");

while([Link]() != null)

[Link]([Link]() + " ");

[Link]();

The EnumSet Class

EnumSet extends AbstractSet and implements Set. It is specifically for use with keys of an enum type.
It is a generic class that has this declaration:

class EnumSet<E extends Enum<E>>

Here, E specifies the elements. Notice that E must extend Enum, which enforces the requirement that
the elements must be of the specified enum type.

2. Accessing a Collection via an Iterator

An iterator, which is an object that implements either the Iterator or the list iterator interface.

Iterator enables you to cycle through a collection, obtaining or removing elements.

ListIterator extends Iterator to allow bidirectional traversal of a list, and the modification of elements.
Iterator and ListIterator are generic interfaces which are declared as shown here:

Get more study materials and resources at VTUCrack


Date: 12/2/2025

interface Iterator<E>

interface ListIterator <E>

Here, E specifies the type of objects being iterated.

2.1 Using an Iterator

In general, to use an iterator to cycle through the contents of a collection, follow these steps:

1. Obtain an iterator to the start of the collection by calling the collection’s iterator( ) method.

2. Set up a loop that makes a call to hasNext( ). Have the loop iterate as long as hasNext( ) returns true.

3. Within the loop, obtain each element by calling next( ).

The following example implements these steps, demonstrating both the Iterator and ListIterator
interfaces. It uses an ArrayList object, but the general principles apply to any type of collection. Of
course, ListIterator is available only to those collections that implement the List interface.

// Demonstrate iterators.

import [Link].*;

class IteratorDemo {

public static void main(String args[]) {

// Create an array list.

ArrayList<String> al = new ArrayList<String>();

// Add elements to the array list.

Get more study materials and resources at VTUCrack


Date: 12/2/2025

[Link]("C");

[Link]("A");

[Link]("E");

[Link]("B");

[Link]("D");

[Link]("F");

// Use iterator to display contents of al.

[Link]("Original contents of al: ");

Iterator<String> itr = [Link]();

while([Link]()) {

String element = [Link]();

[Link](element + " ");

[Link]();

// Modify objects being iterated.

ListIterator<String> litr = [Link]();

while([Link]()) {

String element = [Link]();

[Link](element + "+");

[Link]("Modified contents of al: ");

itr = [Link]();

while([Link]()) {

String element = [Link]();

[Link](element + " ");

Get more study materials and resources at VTUCrack


Date: 12/2/2025

[Link]();

// Now, display the list backwards.

[Link]("Modified list backwards: ");

while([Link]()) {

String element = [Link]();

[Link](element + " ");

[Link]();

The For-Each Alternative to Iterators

// Use the for-each for loop to cycle through a collection.

import [Link].*;

class ForEachDemo {

public static void main(String args[]) {

// Create an array list for integers.

ArrayList<Integer> vals = new ArrayList<Integer>();

// Add values to the array list.

[Link](1);

[Link](2);

[Link](3);

[Link](4);

[Link](5);

Get more study materials and resources at VTUCrack


Date: 12/2/2025

// Use for loop to display the values.

[Link]("Original contents of vals: ");

for(int v : vals)

[Link](v + " ");

[Link]();

// Now, sum the values by using a for loop.

int sum = 0;

for(int v : vals)

sum += v;

[Link]("Sum of values: " + sum);

2.2 Storing User-Defined Classes in Collections

// A simple mailing list example.

import [Link].*;

class Address {

private String name;

private String street;

private String city;

private String state;

private String code;

Address(String n, String s, String c,

String st, String cd) {

name = n;

Get more study materials and resources at VTUCrack


Date: 12/2/2025

street = s;

city = c;

state = st;

code = cd;

public String toString() {

return name + "\n" + street + "\n" + city + " " + state + " " + code;

class MailList {

public static void main(String args[]) {

LinkedList<Address> ml = new LinkedList<Address>();

// Add elements to the linked list.

[Link](new Address("J.W. West", "11 Oak Ave","Urbana", "IL", "61801"));

[Link](new Address("Ralph Baker", "1142 Maple Lane","Mahomet", "IL", "61853"));

[Link](new Address("Tom Carlton", "867 Elm St","Champaign", "IL", "61820"));

// Display the mailing list.

for(Address element : ml)

[Link](element + "\n");

[Link]();

Get more study materials and resources at VTUCrack


Date: 12/2/2025

2.3 The RandomAccess Interface


1. Marker Interface:
o RandomAccess is a marker interface (contains no methods).
2. Indicates Efficient Random Access:
o Implementing this interface signals that a collection supports efficient random access
to its elements.
3. Performance Consideration:
o Even if a collection supports random access, it may not always be efficient, especially
for large collections.
4. Runtime Check:
o Client code can use instanceof to check if a collection implements RandomAccess and
decide its suitability for certain operations.
5. Implementing Classes:
o ArrayList and legacy Vector implement RandomAccess, among others.

**********************************************************************************

Working with Maps


In Java, Map is an interface that stores data in the form of key–value pairs. Each key is associated
with exactly one value. The keys must be unique, but the values may be duplicated.

Even though Map is part of the Java Collection Framework, it does not extend the Collection
interface.

Because Map does not store single elements, it stores pairs of elements.

Key → Value

Map<Integer, String> map = new HashMap<>();

[Link](1, "Ravi");

[Link](2, "Anita");

[Link](3, "Kumar");

Get more study materials and resources at VTUCrack


Date: 12/2/2025

Difference Between Map and Set

3.1 The Map Interfaces


Because the map interfaces define the character and nature of maps, this discussion of maps begins
with them. The following interfaces support maps:
The Map Interface
The Map interface maps unique keys to values. A key is an object that you use to retrieve a value at a
later date. Given a key and a value, you can store the value in a Map object. After the value is stored,
you can retrieve it by using its key. Map is generic and is declared as shown here:
interface Map<K, V>
Here, K specifies the type of keys, and V specifies the type of values.

Get more study materials and resources at VTUCrack


Date: 12/2/2025

The SortedMap Interface

The SortedMap interface extends Map. It ensures that the entries are maintained in ascending order
based on the keys. SortedMap is generic and is declared as shown here:

interface SortedMap<K, V>

Here, K specifies the type of keys, and V specifies the type of values.

The NavigableMap Interface

The NavigableMap interface was added by Java SE 6. It extends SortedMap and declares the behavior
of a map that supports the retrieval of entries based on the closest match to a given key or keys.
NavigableMap is a generic interface that has this declaration:

interface NavigableMap<K, V>

Get more study materials and resources at VTUCrack


Date: 12/2/2025

Here, K specifies the type of the keys, and V specifies the type of the values associated with the keys.

The [Link] Interface

The [Link] interface enables you to work with a map entry. Recall that the entrySet( ) method
declared by the Map interface returns a Set containing the map entries. Each of these set elements is a
[Link] object. [Link] is generic and is declared like this:

interface [Link]<K, V>

Here, K specifies the type of keys, and V specifies the type of values.

Get more study materials and resources at VTUCrack


Date: 12/2/2025

The Map Classes

Several classes provide implementations of the map interfaces. The classes that can be used for maps
are summarized here:

The HashMap Class

The HashMap class extends AbstractMap and implements the Map interface. It uses a hash table to
store the map. This allows the execution time of get( ) and put( ) to remain constant even for large sets.
HashMap is a generic class that has this declaration:

class HashMap<K, V>

Here, K specifies the type of keys, and V specifies the type of values. The following constructors are
defined: HashMap( ) HashMap(Map m) HashMap(int capacity) HashMap(int capacity, float fillRatio)

import [Link].*;

class HashMapDemo {

public static void main(String args[]) {

// Create a hash map.

HashMap<String, Double> hm = new HashMap<String, Double>();

// Put elements to the map

[Link]("John Doe", new Double(3434.34));

[Link]("Tom Smith", new Double(123.22));

Get more study materials and resources at VTUCrack


Date: 12/2/2025

[Link]("Jane Baker", new Double(1378.00));

[Link]("Tod Hall", new Double(99.22));

[Link]("Ralph Smith", new Double(-19.08));

// Get a set of the entries.

Set<[Link]<String, Double>> set = [Link]();

// Display the set.


John Doe: 3434.34
for([Link]<String, Double> me : set) { Tom Smith: 123.22
Jane Baker: 1378.0
[Link]([Link]() + ": "); Tod Hall: 99.22
Ralph Smith: -19.08
[Link]([Link]());
John Doe's new balance: 4434.34
}

[Link]();

// Deposit 1000 into John Doe's account.

double balance = [Link]("John Doe");

[Link]("John Doe", balance + 1000);

[Link]("John Doe's new balance: " + [Link]("John Doe"));

The TreeMap Class

The TreeMap class extends AbstractMap and implements the NavigableMap interface. It creates maps
stored in a tree structure. A TreeMap provides an efficient means of storing key/value pairs in sorted
order and allows rapid retrieval. You should note that, unlike a hash map, a tree map guarantees that its
elements will be sorted in ascending key order.

TreeMap is a generic class that has this declaration:

class TreeMap<K, V>

Here, K specifies the type of keys, and V specifies the type of values.

The following TreeMap constructors are defined:

Get more study materials and resources at VTUCrack


Date: 12/2/2025

 TreeMap( )
 TreeMap(Comparator<? super K> comp)
 TreeMap(Map<? extends K, ? extends V> m)
 TreeMap(SortedMap<K, ? extends V> sm)

import [Link].*;

class TreeMapDemo {

public static void main(String args[]) {

// Create a tree map.

TreeMap<String, Double> tm = new TreeMap<String, Double>();

// Put elements to the map.

[Link]("John Doe", new Double(3434.34));

[Link]("Tom Smith", new Double(123.22));

[Link]("Jane Baker", new Double(1378.00));

[Link]("Tod Hall", new Double(99.22));

[Link]("Ralph Smith", new Double(-19.08));

// Get a set of the entries.

Set<[Link]<String, Double>> set = [Link]();

// Display the elements.

for([Link]<String, Double> me : set) {

[Link]([Link]() + ": ");

[Link]([Link]());

[Link]();

// Deposit 1000 into John Doe's account.

double balance = [Link]("John Doe");

[Link]("John Doe", balance + 1000);

[Link]("John Doe's new balance: " +

[Link]("John Doe"));

Get more study materials and resources at VTUCrack


Date: 12/2/2025

The LinkedHashMap Class

LinkedHashMap extends HashMap. It maintains a linked list of the entries in the map, in the order in
which they were inserted. This allows insertion-order iteration over the map. That is, when iterating
through a collection-view of a LinkedHashMap, the elements will be returned in the order in which
they were inserted.

LinkedHashMap is a generic class that has this declaration:

class LinkedHashMap<K, V>

Here, K specifies the type of keys, and V specifies the type of values

LinkedHashMap defines the following constructors:

 LinkedHashMap( )
 LinkedHashMap(Map<? extends K, ? extends V> m)
 LinkedHashMap(int capacity)
 LinkedHashMap(int capacity, float fillRatio)
 LinkedHashMap(int capacity, float fillRatio, boolean Order)

import [Link].*;

class LinkedHashMapDemo {
public static void main(String[] args) {

// Create a LinkedHashMap
LinkedHashMap<Integer, String> map = new LinkedHashMap<>();

// Add elements (key, value)


[Link](101, "Ravi");
[Link](102, "Anita");
[Link](103, "Kumar");
[Link](104, "Divya");

// Display the map


[Link](map);
}
}
{101=Ravi, 102=Anita, 103=Kumar, 104=Divya}
Order is same as insertion order.

Get more study materials and resources at VTUCrack


Date: 12/2/2025

The IdentityHashMap Class

IdentityHashMap extends AbstractMap and implements the Map interface. It is similar to HashMap
except that it uses reference equality when comparing elements. IdentityHashMap is a generic class
that has this declaration:
IdentityHashMap is a Map class that uses == to compare keys, not equals().
class IdentityHashMap<K, V>

Here, K specifies the type of key, and V specifies the type of value. The API documentation explicitly
states that IdentityHashMap is not for general use.
import [Link].*;

class IdentityHashMapDemo {
public static void main(String[] args) {

IdentityHashMap<String, Integer> map = new IdentityHashMap<>();

String s1 = new String("Java");


String s2 = new String("Java"); // Same value, different object

[Link](s1, 10); // if (key1 == key2)


[Link](s2, 20); // IdentityHashMap –java internally checks

[Link]("Size: " + [Link]());


[Link](map);
}
}
Size: 2
{Java=10, Java=20}

The EnumMap Class

EnumMap extends AbstractMap and implements Map. It is specifically for use with keys of an enum
type. It is a generic class that has this declaration:

class EnumMap<K extends Enum<K>, V>

Get more study materials and resources at VTUCrack


Date: 12/2/2025

Here, K specifies the type of key, and V specifies the type of value.

Notice that K must extend Enum<K>, which enforces the requirement that the keys must be of an
enum type.

EnumMap defines the following constructors:

 EnumMap(Class<K> kType)
 EnumMap(Map<K, ? extends V> m)
 EnumMap(EnumMap<K, ? extends V> em)

import [Link].*;

enum Day {
MON, TUE, WED, THU, FRI
}

class EnumMapDemo {
public static void main(String[] args) {

EnumMap<Day, String> map = new EnumMap<>([Link]);

[Link]([Link], "Work");
[Link]([Link], "Study");
[Link]([Link], "Play");

[Link](map);
}
}

{MON=Work, TUE=Study, WED=Play}

*********************************************************************************

Comparators

Comparator interface in Java is used to order the objects of user-defined classes. Comparator is a
generic interface that has this declaration:

interface Comparator<T>

Here, T specifies the type of objects being compared.

The Comparator interface defines two methods: compare( ) and equals( ). The compare( ) method,
shown here, compares two elements for order:

int compare(T obj1, T obj2)

obj1 and obj2 are the objects to be compared. This method returns zero if the objects are [Link]
returns a positive value if obj1 is greater than obj2.

Using a Comparator

Get more study materials and resources at VTUCrack


Date: 12/2/2025
The following is an example that demonstrates the power of a custom comparator. It implements the
compare( ) method for strings that operates in reverse of normal.

// Use a custom comparator.

import [Link].*;

// Custom Comparator class


class MyComp implements Comparator<String> {

// Reverse sorting logic


public int compare(String a, String b) {
return [Link](a); // reverse order
}
}

public class CompDemo {

public static void main(String args[]) {

// Create TreeSet with custom comparator


TreeSet<String> ts = new TreeSet<String>(new MyComp());

// Add elements
[Link]("C");
[Link]("A");
[Link]("B");
[Link]("E");
[Link]("F");
[Link]("D");

// Display elements
[Link]("Elements in reverse sorted order:");
for(String element : ts) {
[Link](element + " ");
}
}
}

Elements in reverse sorted order:


FEDCBA

Get more study materials and resources at VTUCrack


Date: 12/2/2025

The Collection Algorithms

The Collections Framework defines several algorithms that can be applied to collections and maps.
These algorithms are defined as static methods within the Collections class.

Get more study materials and resources at VTUCrack


Date: 12/2/2025

Collections defines three static variables: EMPTY_SET, EMPTY_LIST, and EMPTY_MAP. All are immutable.

import [Link].*;

class AlgorithmsDemo {

public static void main(String args[]) {

// Create and initialize linked list.

LinkedList<Integer> ll = new LinkedList<Integer>();

[Link](-8);

[Link](20);

[Link](-20);

[Link](8);

// Create a reverse order comparator.

Comparator<Integer> r = [Link]();

// Sort list by using the comparator.

[Link](ll, r);

[Link]("List sorted in reverse: ");

for(int i : ll)

[Link](i+ " ");

[Link]();

// Shuffle list.

[Link](ll);

// Display randomized list.

[Link]("List shuffled: ");

for(int i : ll)

[Link](i + " ");

Get more study materials and resources at VTUCrack


Date: 12/2/2025

[Link]();

[Link]("Minimum: " + [Link](ll));

[Link]("Maximum: " + [Link](ll));

************************************************************************************************

Arrays

The Arrays class provides various methods that are useful when working with arrays. These methods
help bridge the gap between collections and arrays. Each method defined by Arrays is examined in this
[Link] asList( ) method returns a List that is backed by a specified array. In other words, both the
list and the array refer to the same location. It has the following signature:

static <T> List asList(T ... array)

Here, array is the array that contains the data.

The binarySearch( ) method uses a binary search to find a specified value. This method must be
applied to sorted arrays

 static int binarySearch(byte array[ ], byte value)


 static int binarySearch(char array[ ], char value)
 static int binarySearch(double array[ ], double value)
 static int binarySearch(float array[ ], float value)
 static int binarySearch(int array[ ], int value)
 static int binarySearch(long array[ ], long value)
 static int binarySearch(short array[ ], short value)
 static int binarySearch(Object array[ ], Object value)
 static <T> int binarySearch(T[ ] array, T value, Comparator<? super T> c)

Here, array is the array to be searched, and value is the value to be located. The last two forms throw a
ClassCastException if array contains elements that cannot be compared (for example, Double and
StringBuffer) or if value is not compatible with the types in array.

The copyOf( ) method was added by Java SE 6. It returns a copy of an array and has the following
forms:

 static boolean[ ] copyOf(boolean[ ] source, int len)


 static byte[ ] copyOf(byte[ ] source, int len)
 static char[ ] copyOf(char[ ] source, int len)

Get more study materials and resources at VTUCrack


Date: 12/2/2025

 static double[ ] copyOf(double[ ] source, int len)


 static float[ ] copyOf(float[ ] source, int len)
 static int[ ] copyOf(int[ ] source, int len)
 static long[ ] copyOf(long[ ] source, int len)
 static short[ ] copyOf(short[ ] source, int len)
 static <T> T[ ] copyOf(T[ ] source, int len)
 static <T,U> T[ ] copyOf(U[ ] source, int len, Class<? extends T[ ]> resultT)

The original array is specified by source, and the length of the copy is specified by len. If the copy is
longer than source, then the copy is padded with zeros (for numeric arrays), nulls (for object
arrays), or false (for boolean arrays). If the copy is shorter than source, then the copy is truncated.
In the last form, the type of resultT becomes the type of the array returned. If len is negative, a
NegativeArraySizeException is thrown. If source is null, a NullPointerException is thrown. If
resultT is incompatible with the type of source, an ArrayStoreException is thrown.

The copyOfRange( ) method was also added by Java SE 6. It returns a copy of a range within an array
and has the following forms:

 static boolean[ ] copyOfRange(boolean[ ] source, int start, int end)


 static byte[ ] copyOfRange(byte[ ] source, int start, int end)
 static char[ ] copyOfRange(char[ ] source, int start, int end)
 static double[ ] copyOfRange(double[ ] source, int start, int end)
 static float[ ] copyOfRange(float[ ] source, int start, int end)
 static int[ ] copyOfRange(int[ ] source, int start, int end)
 static long[ ] copyOfRange(long[ ] source, int start, int end)
 static short[ ] copyOfRange(short[ ] source, int start, int end)
 static <T> T[ ] copyOfRange(T[ ] source, int start, int end)
 static <T,U> T[ ] copyOfRange(U[ ] source, int start, int end,Class<? extends T[ ]> resultT)

The equals( ) method returns true if two arrays are equivalent. Otherwise, it returns false.

The equals( ) method has the following forms:

 static boolean equals(boolean array1[ ], boolean array2[ ])


 static boolean equals(byte array1[ ], byte array2[ ])
 static boolean equals(char array1[ ], char array2[ ])
 static boolean equals(double array1[ ], double array2[ ])
 static boolean equals(float array1[ ], float array2[ ])
 static boolean equals(int array1[ ], int array2[ ])
 static boolean equals(long array1[ ], long array2[ ])
 static boolean equals(short array1[ ], short array2[ ])
 static boolean equals(Object array1[ ], Object array2[ ])

Here, array1 and array2 are the two arrays that are compared for equality

Get more study materials and resources at VTUCrack


Date: 12/2/2025

The fill( ) method assigns a value to all elements in an array. In other words, it fills an array with a
specified value. The fill( ) method has two versions. The first version, which has the following forms,
fills an entire array:

 static void fill(boolean array[ ], boolean value)


 static void fill(byte array[ ], byte value)
 static void fill(char array[ ], char value)
 static void fill(double array[ ], double value)
 static void fill(float array[ ], float value)
 static void fill(int array[ ], int value)
 static void fill(long array[ ], long value)
 static void fill(short array[ ], short value)
 static void fill(Object array[ ], Object value)

Here, value is assigned to all elements in array.

The second version of the fill( ) method assigns a value to a subset of an array. Its forms are shown
here:

 static void fill(boolean array[ ], int start, int end, boolean value)
 static void fill(byte array[ ], int start, int end, byte value)
 static void fill(char array[ ], int start, int end, char value)
 static void fill(double array[ ], int start, int end, double value)
 static void fill(float array[ ], int start, int end, float value)
 static void fill(int array[ ], int start, int end, int value)
 static void fill(long array[ ], int start, int end, long value)
 static void fill(short array[ ], int start, int end, short value)
 static void fill(Object array[ ], int start, int end, Object value)

Here, value is assigned to the elements in array from position start to position end–1.

The sort( ) method sorts an array so that it is arranged in ascending order. The sort( ) method has two
versions. The first version, shown here, sorts the entire array:

 static void sort(byte array[ ])


 static void sort(char array[ ])
 static void sort(double array[ ])
 static void sort(float array[ ])
 static void sort(int array[ ])
 static void sort(long array[ ])
 static void sort(short array[ ])
 static void sort(Object array[ ])
 static <T> void sort(T array[ ], Comparator<? super T> c)

Here, array is the array to be sorted. In the last form, c is a Comparator that is used to order the
elements of array

Get more study materials and resources at VTUCrack


Date: 12/2/2025

The second version of sort( ) enables you to specify a range within an array that you want to sort. Its
forms are shown here:

 static void sort(byte array[ ], int start, int end)


 static void sort(char array[ ], int start, int end)
 static void sort(double array[ ], int start, int end)
 static void sort(float array[ ], int start, int end)
 static void sort(int array[ ], int start, int end)
 static void sort(long array[ ], int start, int end)
 static void sort(short array[ ], int start, int end)
 static void sort(Object array[ ], int start, int end)
 static <T> void sort(T array[ ], int start, int end, Comparator<? super T> c)

Here, the range beginning at start and running through end–1 within array will be sorted.

The following program illustrates how to use some of the methods of the Arrays class:

// Demonstrate Arrays

import [Link].*;

class ArraysDemo {

public static void main(String args[]) {

// Allocate and initialize array.

int array[] = new int[10];

for(int i = 0; i < 10; i++)

array[i] = -3 * i;

// Display, sort, and display the array.

[Link]("Original contents: ");

display(array);

[Link](array);

[Link]("Sorted: ");

display(array);

// Fill and display the array.

[Link](array, 2, 6, -1);

Get more study materials and resources at VTUCrack


Date: 12/2/2025

[Link]("After fill(): ");

display(array);

// Sort and display the array.

[Link](array);

[Link]("After sorting again: ");

display(array);

// Binary search for -9.

[Link]("The value -9 is at location ");

int index =

[Link](array, -9);

[Link](index);

static void display(int array[]) {

for(int i: array)

[Link](i + " ");

[Link]();

*********************************************************************************
Legacy classes are older collection classes that existed before the introduction of the Java

Collections Framework and are retained in Java for compatibility with old programs.

The Legacy Classes and Interfaces

The legacy classes defined by [Link] are shown here:

Dictionary Hashtable Properties Stack Vector

There is one legacy interface called Enumeration. The following sections examine Enumeration and
each of the legacy classes, in turn.

The Enumeration Interface

Get more study materials and resources at VTUCrack


Date: 12/2/2025

The Enumeration interface defines the methods by which you can enumerate (obtain one at a time) the
elements in a collection of objects. This legacy interface has been superseded by Iterator

It has this declaration:

interface Enumeration<E>

where E specifies the type of element being enumerated.

Enumeration specifies the following two methods:

 boolean hasMoreElements( )
 E nextElement( )

When implemented, hasMoreElements( ) must return true while there are still more elements to
extract, and false when all the elements have been enumerated. nextElement( ) returns the next
object in the enumeration. That is, each call to nextElement( ) obtains the next object in the
enumeration. It throws NoSuchElementException when the enumeration is complete.

Vector

Vector implements a dynamic array. It is similar to ArrayList, but with two differences: Vector is
synchronized, and it contains many legacy methods that are not part of the Collections Framework.
With the advent of collections, Vector was reengineered to extend AbstractList and to implement
the List interface. With the release of JDK 5, it was retrofitted for generics and reengineered to
implement Iterable. This means that Vector is fully compatible with collections, and a Vector can
have its contents iterated by the enhanced for loop.

Vector is declared like this:

class Vector<E>

Here, E specifies the type of element that will be stored.

Here are the Vector constructors:

 Vector( )
 Vector(int size)
 Vector(int size, int incr)
 Vector(Collection<? extends E> c)

The first form creates a default vector, which has an initial size of 10. The second form creates a vector
whose initial capacity is specified by size. The third form creates a vector whose initial capacity is
specified by size and whose increment is specified by incr. The increment specifies the number of
elements to allocate each time that a vector is resized upward.

Vector defines these protected data members:

Get more study materials and resources at VTUCrack


Date: 12/2/2025

 int capacityIncrement;
 int elementCount;
 Object[ ] elementData;

The increment value is stored in capacityIncrement. The number of elements currently in the vector is
stored in elementCount. The array that holds the vector is stored in elementData.

// Demonstrate various Vector operations.

import [Link].*;

class VectorDemo {

public static void main(String args[]) {

// initial size is 3, increment is 2

Vector<Integer> v = new Vector<Integer>(3, 2);

[Link]("Initial size: " + [Link]());

[Link]("Initial capacity: " +

Get more study materials and resources at VTUCrack


Date: 12/2/2025

[Link]());

[Link](1);

[Link](2);

[Link](3);

[Link](4);

[Link]("Capacity after four additions: " + [Link]());

[Link](5);

[Link]("Current capacity: " + [Link]());

[Link](6);

[Link](7);

[Link]("Current capacity: " + [Link]());

[Link](9);

[Link](10); Initial size: 0


Initial capacity: 3
Capacity after four additions: 5
[Link]("Current capacity: " + [Link]()); Current capacity: 5
Current capacity: 7
[Link](11); Current capacity: 9
First element: 1
v. addElement(12); Last element: 12
Vector contains 3.
[Link]("First element: " + [Link]());
Elements in vector:
1 2 3 4 5 6 7 9 10 11 12
[Link]("Last element: " + [Link]());

if([Link](3))

[Link]("Vector contains 3.");

// Enumerate the elements in the vector.

Enumeration vEnum = [Link]();

[Link]("\nElements in vector:");

while([Link]())

[Link]([Link]() + " ");

Get more study materials and resources at VTUCrack


Date: 12/2/2025

[Link]();

// Use an iterator to display contents.

Iterator<Integer> vItr = [Link]();

[Link]("\nElements in vector:");

while([Link]())

[Link]([Link]() + " ");

[Link]();

You can also use a for-each for loop to cycle through a Vector, as the following version of the
preceding code shows:

// Use an enhanced for loop to display contents.

[Link]("\nElements in vector:");

for(int i : v)

[Link](i + " ");

[Link]();

Stack
Stack is a subclass of Vector that implements a standard last-in, first-out stack. Stack only defines the
default constructor, which creates an empty stack. With the release of JDK 5, Stack was retrofitted for
generics and is declared as shown here:

class Stack<E>

Here, E specifies the type of element stored in the stack.

Get more study materials and resources at VTUCrack


Date: 12/2/2025

// Demonstrate the Stack class.

import [Link].*;

class StackDemo {
stack: []
static void showpush(Stack<Integer> st, int a) { push(42)
stack: [42]
[Link](a); push(66)
stack: [42, 66]
[Link]("push(" + a + ")"); push(99)
stack: [42, 66, 99]
[Link]("stack: " + st); pop -> 99
stack: [42, 66]
pop -> 66
} stack: [42]
pop -> 42
static void showpop(Stack<Integer> st) { stack: []
pop -> empty stack
[Link]("pop -> ");

Integer a = [Link]();

[Link](a);

[Link]("stack: " + st);

public static void main(String args[]) {

Stack<Integer> st = new Stack<Integer>();

[Link]("stack: " + st);

showpush(st, 42);

showpush(st, 66);

showpush(st, 99);

showpop(st);

showpop(st);

showpop(st);

try {

Get more study materials and resources at VTUCrack


Date: 12/2/2025

showpop(st);

} catch (EmptyStackException e) {

[Link]("empty stack");

Dictionary

Dictionary is an abstract class that represents a key/value storage repository and operates much like
Map. Given a key and value, you can store the value in a Dictionary object. Once the value is stored,
you can retrieve it by using its key.

. It is declared as shown here:

class Dictionary<K, V>

Here, K specifies the type of keys, and V specifies the type of values.

import [Link].*;

class DictDemo {
public static void main(String args[]) {
Dictionary<Integer, String> d = new Hashtable<>();

[Link](1, "Java");
[Link](2, "Python");

[Link]([Link](1)); // Java
}
Get more study materials and resources at VTUCrack
Date: 12/2/2025
}

Hashtable

Hashtable was part of the original [Link] and is a concrete implementation of a Dictionary.

Hashtable was made generic by JDK 5. It is declared like this:

class Hashtable<K, V>

Here, K specifies the type of keys, and V specifies the type of values.

A hash table can only store objects that override the hashCode( ) and equals( ) methods that are
defined by Object

The Hashtable constructors are shown here: Hashtable( ) Hashtable(int size) Hashtable(int size, float
fillRatio) Hashtable(Map m)

index = key % table_size


// Demonstrate a Hashtable.
Hash Function
import [Link].*; ↓
Key → h(key) → Index
class HTDemo {
Index | Bucket (Key, Value)
----------------------------
public static void main(String args[]) { 0 | (10, "Java")
1 | (21, "AI")
Hashtable<String, Double> balance = new Hashtable<String, Double>(); 2 | (32, "Python")
3 | (43, "C++")
Enumeration<String> names;

String str;
Get more study materials and resources at VTUCrack
Date: 12/2/2025
double bal;

[Link]("John Doe", 3434.34);

[Link]("Tom Smith", 123.22);

[Link]("Jane Baker", 1378.00);

[Link]("Tod Hall", 99.22);

[Link]("Ralph Smith", -19.08);

// Show all balances in hashtable.

names = [Link]();

while([Link]()) {

str = [Link]();

[Link](str + ": " + [Link](str));

[Link]();

// Deposit 1,000 into John Doe's account.

bal = [Link]("John Doe");

[Link]("John Doe", bal+1000);

[Link]("John Doe's new balance: " + [Link]("John Doe"));

// Use iterators with a Hashtable.

import [Link].*;

class HTDemo2 {

public static void main(String args[]) {

Hashtable<String, Double> balance = new Hashtable<String, Double>();

String str;

Get more study materials and resources at VTUCrack


Date: 12/2/2025
double bal;

[Link]("John Doe", 3434.34);

[Link]("Tom Smith", 123.22);

[Link]("Jane Baker", 1378.00);

[Link]("Tod Hall", 99.22);

[Link]("Ralph Smith", -19.08);

// Show all balances in hashtable.

// First, get a set view of the keys.

Set<String> set = [Link]();

// Get an iterator.

Iterator<String> itr = [Link]();

while([Link]()) {

str = [Link]();

[Link](str + ": " + [Link](str));

[Link]();

// Deposit 1,000 into John Doe's account.

bal = [Link]("John Doe");

[Link]("John Doe", bal+1000);

[Link]("John Doe's new balance: " + [Link]("John Doe"));

Properties

Properties is a subclass of Hashtable. It is used to maintain lists of values in which the key is a String
and the value is also a String. The Properties class is used by many other Java classes. For example, it
is the type of object returned by [Link]( ) when obtaining environmental values.
Although the Properties class, itself, is not generic, several of its methods are.
Get more study materials and resources at VTUCrack
Date: 12/2/2025

Properties defines the following instance variable:

Properties defaults;

This variable holds a default property list associated with a Properties object. Properties defines these
constructors:

 Properties( )
 Properties(Properties propDefault)

The first version creates a Properties object that has no default values.

// Demonstrate a Property list.

import [Link].*;

class PropDemo {

public static void main(String args[]) {

Properties capitals = new Properties();

[Link]("Illinois", "Springfield");

[Link]("Missouri", "Jefferson City");

[Link]("Washington", "Olympia");
Get more study materials and resources at VTUCrack
Date: 12/2/2025
[Link]("California", "Sacramento");

[Link]("Indiana", "Indianapolis");

// Get a set-view of the keys.

Set states = [Link]();

// Show all of the states and capitals.

for(Object name : states)

[Link]("The capital of " + name + " is " + [Link]((String)name) + ".");

[Link]();

// Look for state not in list -- specify default.

String str = [Link]("Florida", "Not Found");

[Link]("The capital of Florida is "+ str + ".");

Using store( ) and load( )

One of the most useful aspects of Properties is that the information contained in a Properties object can
be easily stored to or loaded from disk with the store( ) and load( ) methods.

/* A simple telephone number database that uses a property list. */

import [Link].*;

import [Link].*;

class Phonebook {

public static void main(String args[])

throws IOException

Properties ht = new Properties();

BufferedReader br = new BufferedReader(new InputStreamReader([Link]));

String name, number;

FileInputStream fin = null;

Get more study materials and resources at VTUCrack


Date: 12/2/2025

boolean changed = false;

// Try to open [Link] file.

try {

fin = new FileInputStream("[Link]");

} catch(FileNotFoundException e) {

// ignore missing file

/* If phonebook file already exists,

load existing telephone numbers. */

try {

if(fin != null) {

[Link](fin);

[Link]();

} catch(IOException e) {

[Link]("Error reading file.");

// Let user enter new names and numbers.

do {

[Link]("Enter new name" + " ('quit' to stop): ");

name = [Link]();

if([Link]("quit")) continue;

[Link]("Enter number: ");

number = [Link]();

[Link](name, number);

Get more study materials and resources at VTUCrack


Date: 12/2/2025

changed = true;

} while(![Link]("quit"));

// If phone book data has changed, save it.

if(changed) {

FileOutputStream fout = new FileOutputStream("[Link]");

[Link](fout, "Telephone Book");

[Link]();

// Look up numbers given a name.

do {

[Link]("Enter name to find" + " ('quit' to quit): ");

name = [Link]();

if([Link]("quit")) continue;

number = (String) [Link](name);

[Link](number);

} while(![Link]("quit"));

****************************************************************************

Comparators

Comparator interface in Java is used to order the objects of user-defined classes. Comparator is a
generic interface that has this declaration:

interface Comparator<T>

Here, T specifies the type of objects being compared.

The Comparator interface defines two methods: compare( ) and equals( ).

Get more study materials and resources at VTUCrack


Date: 12/2/2025

The compare( ) method, shown here, compares two elements for order:

int compare(T obj1, T obj2)

obj1 and obj2 are the objects to be compared. This method returns zero if the objects are equal. It
returns a positive value if obj1 is greater than obj2.
import [Link].*;

// Student class
class Student {
int age;
String name;

Student(int age, String name) {


[Link] = age;
[Link] = name;
}
}

// Comparator class to sort by age


class AgeComparator implements Comparator<Student> {
public int compare(Student s1, Student s2) {
return [Link] - [Link]; // ascending order// If result is negative → s1 comes first// If result is negative
→ s1 comes first// If result is positive → s2 comes first
}
}

public class ComparatorDemo {


public static void main(String[] args) {

ArrayList<Student> list = new ArrayList<>();

[Link](new Student(22, "Ravi"));


[Link](new Student(18, "Anu"));
[Link](new Student(25, "Kumar"));

// Sort using Comparator


[Link](list, new AgeComparator());
Get more study materials and resources at VTUCrack
Date: 12/2/2025

// Display result
for (Student s : list) {
[Link]([Link] + " " + [Link]);
}
}
}
The Collection Algorithms

The Collections Framework defines several algorithms that can be applied to collections and maps.
These algorithms are defined as static methods within the Collections class.

Collections define three static variables: EMPTY_SET, EMPTY_LIST, and EMPTY_MAP. All are
immutable.

Java Collection Classes


Java provides a set of standard collection classes that implement Collection interfaces. Some of the
classes provide full implementations that can be used as-is and others are abstract class, providing
skeletal implementations that are used as starting points for creating concrete collections.

[Link]. Class & Description

AbstractCollection
1 Implements most of the Collection interface.

2 AbstractList
Extends AbstractCollection and implements most of the List interface.

AbstractSequentialList
3 Extends AbstractList for use by a collection that uses sequential rather than random
access of its elements.

4 LinkedList
Implements a linked list by extending AbstractSequentialList.

5 ArrayList
Implements a dynamic array by extending AbstractList.

6 AbstractSet
Extends AbstractCollection and implements most of the Set interface.

7 HashSet
Extends AbstractSet for use with a hash table.

8 LinkedHashSet
Extends HashSet to allow insertion-order iterations.

Get more study materials and resources at VTUCrack


Date: 12/2/2025

TreeSet
9
Implements a set stored in a tree. Extends AbstractSet.

AbstractMap
10
Implements most of the Map interface.

HashMap
11
Extends AbstractMap to use a hash table.

TreeMap
12
Extends AbstractMap to use a tree.

LinkedHashMap
13
Extends HashMap to allow insertion-order iterations.

IdentityHashMap
14
Extends AbstractMap and uses reference equality when comparing documents.

Arrays

The Arrays class provides various methods that are useful when working with arrays. These methods
help bridge the gap between collections and arrays. Each method defined by Arrays is examined in
this section. The asList( ) method returns a List that is backed by a specified array. In other words,
both the list and the array refer to the same location. It has the following signature:

static <T> List asList(T ... array)

Here, array is the array that contains the data.

The Legacy Classes and Interfaces

The legacy classes defined by [Link] are shown here:

Dictionary Hashtable Properties Stack Vector

Vector
1 This implements a dynamic array. It is similar to ArrayList, but with some
differences.

2 Stack

Get more study materials and resources at VTUCrack


Date: 12/2/2025

Stack is a subclass of Vector that implements a standard last-in, first-out stack.

Dictionary
3 Dictionary is an abstract class that represents a key/value storage repository and
operates much like Map.

Hashtable
4 Hashtable was part of the original [Link] and is a concrete implementation of a
Dictionary.

Properties
5 Properties is a subclass of Hashtable. It is used to maintain lists of values in
which the key is a String and the value is also a String.

Parting through the collection frameworks - Summary

The Java collections framework gives the programmer access to prepackaged data structures as well as
to algorithms for manipulating them.

A collection is an object that can hold references to other objects. The collection interfaces declare the
operations that can be performed on each type of collection.

The classes and interfaces of the collections framework are in package [Link].

Get more study materials and resources at VTUCrack

You might also like