Static Block, Instance Block and Constructor: Order of Execution

Overview In Java, we have static block, instance block and constructor which gets executed when we create an instance. All of these blocks can be used to write some initialization logic. Have you ever wondered in what sequence these blocks get executed? First Java looks for the existence of “static blocks”. A static keyword is … Read more

Arrays.asList in Java Examples

We generally use Arrays.asList method to copy an object array into a List object. It returns a fixed-size List object from the object array that you have passed to this method. Since Arrays.asList method returns a fixed-size List object, you must remember that you cannot add or remove elements from this List object as you … Read more

[Solved] Why List.add throws UnsupportedOperationException in Java?

If you are getting an UnsupportedOperationException while adding an object to List the reason could be that you are performing this operation on a fixed-size List object. What is a fixed-length object? You must have used Arrays.asList method to convert an array object to List object. If you closely look at the documentation of Arrays.asList … Read more

How to Convert an Array to List in Java?

Though an array is an object in Java, it doesn’t have the required methods to convert it to a List object, it just contains the basic methods that it derived from the Object class. But if you want to convert an array to List, we have other alternatives. Using Arrays.asList(Object[]) Arrays.asList method can take an … Read more

[Solved] error: char cannot be dereferenced

While running a Java program, are you getting “error: char cannot be dereferenced” compilation error in calling methods like equals, isLetter, etc? In this post, we’ll look at the reasons you are getting this error and the solutions to fix it. Why do we get this error? Char cannot be dereferenced – compilation error occurs … Read more