Let’s learn comparable interface in java. Comparable interface in java Comparable interface is present in java.lang package and it contains only one method compareTo(). Declaration: public interface Comparable<T> Parameters: <T> the type of objects that this object may be compared to. compareTo(Object obj) method Declaration: public int compareTo(Object obj) Parameters: obj the object to be…

Read More Comparable interface in java

Let’s learn difference between abstract class and interface in java. Difference between abstract class and interface in java Here’s the difference between abstract class and interface. Abstract class Interface If we know method implementation, but partial implementation then use abstract class. If we know do not know method implementation then use interface. Each method in…

Read More Difference between abstract class and interface in java

Let’s learn difference between class and interface in java. Difference between class and interface in java Here’s the difference between class and interface. Class Interface “Class” keyword is used to declare class. Whereas “interface” keyword is used to declare an interface. Multiple inheritance is not supported in a class whereas interface supports multiple inheritance. A…

Read More Difference between class and interface in java

Let’s learn difference between hashmap and hashset in java. Difference between HashMap and HashSet in java HashSet HashMap HashSet stores only objects. HashMap stores elements in key and value pairs. That is each element has its corresponding key which is used for retrieval during iteration. Insertion order is not preserved. objects inserted are based on…

Read More Difference between HashMap and HashSet in java

Let’s learn recursion in java. Recursion in java Recursion is a process where a method calls itself infinitely or continuously. Recursion program Recursion makes code closely packed and difficult to understand. Here’s an example on infinite recursive function. public class InfiniteRecursiveExample { static void print() { System.out.println(“helloworld”); print(); } public static void main(String[] args) {…

Read More Recursion in java

Let’s learn how to remove duplicates from arraylist in java. How to remove duplicates from ArrayList in java Here the task is to remove duplicates in ArrayList. In the below java program first get given ArrayList with duplicate integer values. Now print ArrayList with duplicate integer values on the console. Create another ArrayList ‘alNew’. Pass…

Read More How to remove duplicates from ArrayList in java