How to reverse a string in Java

In this article, we will show you a few ways to reverse a String in Java. StringBuilder(str).reverse() char[] looping and value swapping. byte looping and value swapping. Apache commons-lang3 For development, always picks the standard StringBuilder(str).reverse() API. For educational purposes, we can study the char[] and byte methods, it involved value swapping and bitwise shifting …

Read more

Java Selection sort example

Selection sort is an in-place comparison sort. It loops and find the first smallest value, swaps it with the first element; loop and find the second smallest value again, swaps it with the second element, repeats third, fourth, fifth smallest values and swaps it, until everything is in correct order. P.S Selection sort is inefficient …

Read more

Java Bubble sort example

Bubble sort is the simplest sorting algorithm, it compares the first two elements, if the first is greater than the second, swaps them, continues doing (compares and swaps) for the next pair of adjacent elements. It then starts again with the first two elements, compares, swaps until no more swaps are required. 1. Explanation #unsorted …

Read more