You are on page 1of 2

LAB SHEET FOR UNIT-2

1. Write a Java program to declare an ArrayList of String type and perform


the following operations:
a) To insert 5 Elements of string type.
b) To insert Element at a specific Index.
c) To retrieve an element (at a specified index) from a given array list.
d) To update an array element by the given element.
e) To delete Element at a specific Index.
f) To search for an element in an array list.
g) To sort the array list.
h) To reverse elements in an array list.
i) To iterate through all the elements of an ArrayList.

2. Write a program that creates an Array List and adds a Loan object, a Date
object, a string, and a Circle object to the list, and use a loop to display all
elements in the list by invoking the objects to String () method.

3. Write a Java Program to declare an LinkedList and perform the


following operations:
a) To Insert the specified element at the specified position.
b) To Insert specified element at the specified position.
c) To Insert specified element at First and Last position.
d) To Iterate a linked list in reverse order.
e) To remove a specified element from a linked list.
f) To retrieve, but not remove, the last element of a linked list.
g) to remove and return the first element of a linked list.
h) To check if a particular element exists in a linked list.
i) To replace an element in a linked list.
j) To check if a linked list is empty or not.

4. Write a Java Program to implement the Queue interface by


 creating the Queue, implementing LinkedList class Class and
perform following operations:
a) Add elements to the queue.
b) Access elements of the queue.
c) Remove elements of the queue.
5. Write a Java Program to implement HashMap methods.
a) To associate the specified value with the specified key in a
HashMap.
b) To count the number of key-value (size) mappings in a map.
c) To copy all mappings from the specified map to another map.
d) To remove all mappings from a map.
e) To check whether a map contains key-value mappings (empty) or
not.
f) To get a collection view of the values contained in this map.

6. Write a Java Program to implement TreeMap methods.


a) to associate the specified value with the specified key in a Tree
Map.
b) to copy Tree Map's content to another Tree Map.
c) to search for a key in a Tree Map.
d) to search for a value in a Tree Map.
e) to get all keys from a Tree Map.
f) to delete all elements from a Tree Map.
g) to get the first (lowest) key and the last (highest) key currently in a
map.

You might also like