Understanding bit more of it

  • Eclipse: Oxygen
  • Java: 1.8

This article generalizes all the tutorials studied so far in the Collections framework. If we define the type of List as Object, we can add all kinds of Objects, such as the Integer, the String and even some characters. Therefore, all the defined techniques can work, except for sort which only works for elements with the same datatype.

In the following example, we replace the type of List from names to Object, which makes it more generic and allows the user to use any type of data without any restriction (Object is the parent class of all the classes).

Output

Element: Chaand

Element: Ed

Element: John

Element: Mia

Element: Some String

Element: 1

Element: 2.0

Element: #

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