![]() |
VOOZH | about |
In Java, Collections like lists, and sets play a crucial role in converting and manipulating the data efficiently. The Conversion of a List of Lists into a HashSet is mainly used to Remove Duplicates and ensures the programmer maintains the unique data of elements.
Input: ListofList = [ [ 1,2,3 ] ,
[ 4,5 ] ,
[ 1,2,3 ] ]
Output: HashSet = [ [ 1,2,3 ] ,
[ 4,5 ] ]
Below is the Program to Convert a List of Lists to HashSet using the Default Constructor:
HashSet: [[10, 20, 30], [40, 50]]
addAll() Method is used with the collection to add the elements in the Collection container.
Below is the implementation of the Program to convert List of lists to HashSet in Java using addAll() Method:
HashSet: [[11, 21, 31], [40, 50]]