Some important techniques

  • Eclipse: Oxygen
  • Java: 1.8

The tutorial shows some important techniques that can be implemented and that save time, for example. The addAll()  method for queues and sets and also implementing the binary search in the same also explore the comparable interface for lists.

The following program demonstrates how to create a list from set items. As this list is created from the set, so duplicate items will be eliminated.

Output

Chaand

Mia

Armaan

John

Aafiya

We can also apply some more collection function on the list. Like we can sort the list.

Output

Aafiya

Armaan

Chaand

John

Mia.

We can search for any element in a list using binarySearch() method. if the element is present in the collection, binarySearch() method return the index position of the element. If the element is not present, binarySearch() returns the negative value.

Output

Aafiya

Armaan

Chaand

John

Mia

-6

Contributed by Poonam Tomar


Full stack Java Developer

   Buy me a coffee!

 

PayTM QR (INDIA)

Download file

Leave a Reply

avatar
  Subscribe  
Notify of
Close Menu