Sort arraylist and collection in java (Comparable and Comparator)

This tutorial shows the use java.lang.Comparable and java.util.Comparator to sort arraylist and collection in java. The arraylist or collection may contain primitive data, string or user defined object. Here is is a good subject for any java programmer. Because if you know and understand how to sort arraylist and collection in Java(Comparable and Comparator) you … Read more

Create instance using class name in Java

You can create instance using class name if Java knows about the class (the class is stored somewhere of the classpath, ie) within the application context. Thus, you can get a reference to this Class and instantiate an its object via the Class class. This technique is applied in many frameworks, web container, for example … Read more

Two ways compare Java Double

This sample shows two ways compare Java Double object with another Double object or two dobule primitive values using methods of java.lang.Double class

Output First number is greater Value c1 = 1 Second number is greater Value c2 = -1

How to loop collection using Iterator object?

I show you three ways to loop collection using Iterator object. Hope you like and choose one to implement for your code. Although there are other ways to do but i recommend these ways for you. Iterate via “iterator loop” The hasNext() method returns true if the iteration has more elements. The next() method returns … Read more

Please share it if you found this useful
Hide Buttons