13.07. Some important techniques

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 functions to 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

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments