Java user defined or custom exception example

Example of user defined exception or custom exception in Java : In java, we have different types of exceptions already available. For example, NullPointerException, ArrayIndexOutOfBoundException , ClassNotFoundException , FileNotFoundException etc. All of these exceptions invokes for specific predefine rules. For example, NullPointerException occurs if we try to do any operation on a null value, ArrayIndexOutOfBoundException […]

Java Example to empty an Arraylist

Empty an arraylist in Java using clear() and removeAll() : To remove all elements from an ArrayList in Java, we have two inbuilt methods : clear() and removeAll(). Both methods can remove all elements from an ArrayList. Both method looks same but there is a difference between them. Even both of them performs differently. In […]