In the following example, reversal string operation is shown in Java language. reverse(s) method completely reverses the string.
public class ReverseString { public static void main(String[] args) { String s = "Hello world!"; System.out.println("Reversed String: " + reverse(s)); } public static String reverse(String str) { StringBuilder strBuilder = new StringBuilder(); char[] strChars = str.toCharArray(); for (int i = strChars.length - 1; i >= 0; i--) { strBuilder.append(strChars[i]); } return strBuilder.toString(); } }
Output:
Reversed String: !dlrow olleH
In the following example, you will see the recursive binary search algorithm implementation in Java language. {% highlight java %} class BinarySearch { 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18...
Although Java is object oriented, not all types are object. There are primitive types as well. Here is a list of all primitive types in Java: Primitive Datatypes: Data Type ...
When we develop code with Java, we often work with files and different types of them. In general, we need compression operations to keep the file content intact and to reduce the file size. Althou...
-
Binary Search