Runtime comparison of string concatenation

One of the mostly asked questions is “How should I do string concatenation?”. And the answer to this question is not very straight forward.  Here I would benchmark the three string concatenation operations. Tools Used I am using jmh to do the benchmarking. And used maven to run the benchmark code  on java 8 as recommended … [Read more…]

Convert List to Array in Java

In this tutorial we will see how to convert a list of objects to an Array.  That can be done by toArray method on the list. We are going to use the below two methods to do the conversion. Both these methods preserve order of the original list being converted. We would also discuss the conversion of … [Read more…]

Mergesort in java

Mergesort is a divide and conquer algorithm. It works by breaking an array into sub-arrays and then recursively sorting the sub-arrays. Steps for Mergesort Divide the list with n elements into n sublists with each sublist having 1 element. We will divide list into 2 sublists by dividing in the middle and then recursively dividing … [Read more…]

How to take input from user in java

The simplest and the easiest way to read the user input in java is by using the Java scanner class. What is scanner class? java.util.Scanner is a simple text scanner that can parse primitive types and strings using regular expressions. The input to Scanner class is broken into tokens using a delimiter pattern, which by … [Read more…]

Autoboxing and its pitfalls

Autoboxing What is Autoboxing? Autoboxing is a feature of Java language introduced in Java 1.5.  When Java compiler makes automatic conversion between the primitive types and their corresponding object wrapper class, it is called autoboxing.  The process of creating a Wrapper class like Float from a primitive type like float is called boxing.  And the process of creating … [Read more…]

Java interview questions, coding in a team

When a programmer joins a team, he is at least expected to have a basic understanding of the process of handling  code within a team. And the following questions have been taken from real world interviews and groups discussions Q. How can a team work on a code that is used by a team of … [Read more…]

Eclipse, svn folder properties

Changes in properties of a folder. When you are adding a file to svn ignore list then you need to commit the top folder. Because you have changed the properties of the folder. svn:ignore list is not a local list. I always thought so. The svn ignore list is in the properties of that folder that exists in … [Read more…]

Quicksort in Java

Quicksort is a divide and conquer algorithm. It works by breaking an array into two sub-arrays and then recursively sort the sub-arrays. Steps for QuickSort Select the pivot element.  Any element that you choose would be called the pivot element. All the elements that are smaller than the pivot element are kept in one array … [Read more…]

Delete nodes from a Tree in Java

In this tutorial we will see how to delete nodes from a Tree. In my last tutorial create and traverse java tree tutorial I showed how to create a tree and then we also looked at an example of traversing the tree. Reference Tree The image below shows the Tree that we will use in this … [Read more…]