Professional Documents
Culture Documents
FG DC
FG DC
FG DC
Sorting: The List interface provides a sort() method that allows you to
sort the elements of the list in their natural order or using a
custom Comparator to define the sorting order.
Searching: The List interface provides several methods for searching,
such as:
contains(): Returns true if the list contains the specified element.
indexOf(): Returns the index of the first occurrence of the
specified element, or -1 if the element is not found.
lastIndexOf(): Returns the index of the last occurrence of the
specified element, or -1 if the element is not found.
binarySearch(): Searches for the specified element using a binary
search algorithm. The list must be sorted in ascending order for this
method to work correctly.
Map:
10. Sorting: Maps are not directly sortable since they are key-value pairs. However, you c
Advantages:
Ordered Collection: Lists maintain the order of elements as
they are inserted and allow positional access to elements
through indexing.
Flexible Size: Lists can dynamically grow or shrink as elements
are added or removed, making them suitable for situations
where the size of the collection may change.
xDisadvantages:
Linear Search: Searching for an element in a list can be slower
compared to other data structures like maps, especially for large lists. It
performs a linear search through the elements until a match is found.
Map:
Advantages:
Key-Value Pairing: Maps store elements as key-value pairs, allowing
efficient lookup and retrieval of values based on their associated keys.
Fast Retrieval: Maps provide fast retrieval of values based on the key.
They use hashing techniques, making lookups faster than linear
searching.
Disadvantages:
11. Unique Keys: Maps require unique keys, and attempting to insert a duplicate key will
overwrite the existing entry. If you need to store multiple values with the same key, a
different approach is required, such as using a MultiMap
12. ) Discuss briefly about
java collection (set, list and
map), compare and contrast
each collection and
advantage and dis advantage
and explain available
methods to sort and search
from each collections.
13.
14.
15. What is java collection?
16.
17. A collection refers to a group of objects
that are gathered and stored together
as a single unit. Java provides the Java
Collections Framework, which is a built-
in library that offers a set of interfaces,
classes, and algorithms to manipulate
and organize collections of objects.
18.
19. The Java Collections Framework
provides a unified and standardized
way of working with collections, making
it easier for developers to handle
groups of objects efficiently. It includes
a hierarchy of interfaces, with the key
interfaces
being Collection, List, Set, Map, and
other
20.
21. What is List interface?
22. The Java collections interface's sub-
interface is called the List interface. It
offers index-based ways to add,
update, remove, and search for
elements. Duplicate
23. y.
24. System.out.println(Set);
25. }
26. }
dy
dx
What is Map?