Java

Let’s learn reverse a string in java. Reverse a string in java Let’s learn following ways or different methods to reverse a string. As we know that String is immutable. String class do not have reverse() method. While StringBuffer class has reverse() method. First let’s learn to reverse a string using ByteArray. class ReverseStringByteArray {…

Read More Reverse a string in java

Let’s learn remove character from string in java. Remove character from string in java In java, String class do not have remove() method. Meanwhile String class have replace() method with overloaded variations like this as shown below. Now let’s see example on overloaded String replace() method. Remove only characters(letters) from string In this example I have…

Read More Remove character from string in java

Let’s learn String length() method in java. String length() method in java length() method in java returns length of this string. The length of the sequence of characters represented by this object. String length() method is specified by CharSequence interface. The length is equal to the number of Unicode code units in the string. Syntax…

Read More String length() method in java

Let’s learn string concatenation in java. String concatenation in java String concatenation is nothing but combining two or more strings to form a new string. Let’s learn few ways to concatenate strings in java. String concatenation using concat() method: String concat() method concatenates specified string to end of given string. Let’s see an example on…

Read More String concatenation in java

Let’s learn java compare two strings. Java compare two strings In java, String is immutable. Meaning, once created String object can’t be changed, they are constant. Below are few ways to compare 2 strings in java. NOTE: Do not use == operator for comparing Strings Because basically equal() method and == operator compare objects to…

Read More Java compare two strings

Let’s learn String toUpperCase() method in java. String toUpperCase() method in java String toUpperCase() method have two variants. String toUpperCase() method in java converts a string to upper case letters. Here’s the String toUpperCase() method example. public class StringToUppercaseDemo { public static void main(String[] args) { String str = “flower brackets”; String strUpper = str.toUpperCase(); System.out.println(strUpper);…

Read More String toUpperCase() method in java

Let’s learn selection sort in java. Selection sort in java In selection sort algorithm smallest element in unsorted array is shifted to its correct position in an array. The number of times sorting takes place will always be one less than the number of integer elements in an array. To select lowest element we need…

Read More Selection sort in java

Let’s learn reverse string array in java. Reverse string array in java Here’s the reverse string array program using for loop. import java.util.Arrays; public class ReverseStringArrayInJava { public static void main(String[] args) { String[] strHierarchy = new String[]{“Junior Developer”,”Senior Developer”,”Team Lead”,”Project Manager”,”Senior Manager”,”CEO”}; System.out.println(“Given string array: ” + Arrays.toString(strHierarchy)); for(int a = 0; a <…

Read More Reverse string array in java