How to Reverse an Integer in Java

In this example, we will see how to reverse an integer in Java using mathematical equations, StringBuffer and StringBuilder classes. Reverse an Integer in Java using Mathematical Equations To reverse an integer mathematically, first thing what we should do is to take out the last digit as a separate integer. That is possible by dividing … Read more

How to read input from User in Java

In this post, we will discuss on how to read input from User using Scanner and InputStreamReader. Scanner(System.in) To read values of known type from standard input, we can use Scanner class. When I say known types, any primitive like int, double, char or a String. Scanner provides various utility methods to read input such … Read more

How to add a List to another List in Java

Collection class in java.util provides addAll method which accepts a list and adds them to the source object. Since, List and ArrayList inherit from Collection, we can use this method to add a List to another List. boolean Collection.addAll(Collection) This method appends all the elements from the new collection to the end of the source … Read more

How to rename a file in Java

To rename a file, we can use File.renameTo() function from java.io package. However, renameTo() function requires a new File object with the new name that we want to name the source file, instead of just passing the new name to renameTo() function. So, to rename a file, we need to create two File objects, one … Read more