Bubble Sort

What is Bubble Sort? Bubble sorting algorithm sort items in a list by repeatedly comparing adjacent elements and swapping them when they are out of order and this process is repeated until it sort the entire list. Bubble Sort Animation A picture is worth a thousand words. I found this interesting bubble sort gif file … 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