Tag «Java»

Selection Sort Implementation in Java

Selection sort is one of the simplest sorting algorithms. It is easy to implement but it is not very efficient. The algorithm divides the input list into two parts: the sublist of items already sorted, which is built up from left to right at the front (left) of the list, and the sublist of items …

Easiest Way to calculate elapsed time in Java

Quite often in our day to day programming, we need to compute how long does a specific portion of the code takes to complete. For e.g; you might want to check how long does a method take to complete.¬† In Java, the simplest way to accomplish this is to use System.nanoTime() method. Following example shows …

Array Bubble Sort in Java

Although Java’s Arrays class has a built-in method to sort an array, it is important for good Java developers to know how to sort an array on their own. Bubble sort is the simplest sorting algorithm.

Java String comparison. The difference between == and equals().

Many Java beginners find it difficult to differentiate between == operator and the “equals()” method when comparing String variables in Java. They assume that both operations perform the same function and either one can be used to compare two string variables. I have even seen many experienced programmers committing the mistake of using “==” to …