When to use static methods in Java | How to use & examples

A Static method is declared with the static keyword. Making a static method in java required when you don’t want a create an object or method is not using any instance variable or method definition will not change or can’t be overridden. This is some reason when to use static methods in java. It’s an Read More…


Java print stack trace to log | Logger class

To print a stack trace to log you Should declare logger and method info(e.toString()) or log(Level.INFO, e.toString()). Logging is the process of writing log messages during the execution of a program to get error and warning messages as well as info messages. The java.util.logging package provides the logging capabilities via the Logger class. In general, at the top of every class, Read More…


Java print stack trace to string | How to Convert Program example

Using Core Java API to print the stack trace to strings provides an easy and efficient way to convert stack trace to string using StringWriter and PrintWriter. A printStackTrace() method is used for get information about exception. You don’t need any special method to convert a print stack trace to a string. In the try-catch-finally exceptions block, we Read More…


When finally block is not executed OR finally block always get executed in Java

The “finally” will be called after the execution of the try or catch code blocks. Some programmers think  finally block always executes, no matter what. But it’s not true. Note: finally will be called after the execution of the try or catch code blocks. Must Read- What is try-catch Java Block? Some condition (cases) where “finally” won’t be called are: System.exit() invoked in block Read More…


Best Way to Initialization ArrayList in one line | Java List

Actually, probably the “best” way to initialize the ArrayList is the method is no needed to create a new List in any way. There are many ways to do this because java versions are changed, First, wee the way then decide which is the Best Way to Initialization ArrayList in one line. Normal Way:- Multiline See below only quite Read More…


Java convert Set to List | ArrayList to HashSet

Java converts Set to List by using many methods like- Loop traverse, ArrayList constructor, addAll method, Java 8 Stream, Guava Library List.newArrayList(set). There is one more easiest way to convert Set to List in Java. Both both Set and List are extended the Collection, so converting Set into the list is quite straightforward. It only Read More…


Array to ArrayList | Create ArrayList from Array in Java

Conversion of Array To ArrayList in Java is the top question in one of the most viewed and voted questions on StackOverflow. You can convert an array to ArrayList using the following ways. Using Arrays.asList() method: Simply pass the array in method. Collections.addAll() method: Create a new list and add array elements using this method Read More…