Saturday 5 November 2016

Why Interface in Java ?

Ans:

1. Support the functionality of multiple inheritance.

2. Achieve fully abstraction.

3. Achieve loose coupling, which is the biggest advantage of interface.

Tuesday 1 November 2016

How to sort ArrayList in JAVA.

To sort values in ArrayList, we use Collections class, and invoke sort() method. consider this example:

package java8s;
 
import java.util.*;
 
public class SortCollectionDemo {
 
public static void main(String[] args)
{
 
    List li = new ArrayList();
 
    li.add("Santosh");
    li.add("Akshay");
    li.add("Tapuuu");
    li.add("Millan);
    li.add("Rakesh");
 
    Collections.sort(li);
 
for(String temp: li)
{
System.out.println("Countries : "+temp);
}
}
}

Output:
Akshay
Millan
Rakesh
Santosh
Tapuuu