Java-Trimming

Trimming To remove whitespace from the beginning and end of a string (but not the interior) you can use the trim( ) method. Program Program Source public class Javaapp { public static void main(String[] args){ String str1 = new String(” haj sof “); System.out.println(str1); System.out.println(“str1.length = “+str1.length()); str1 = str1.trim(); System.out.println(str1); System.out.println(“str1.length = “+str1.length()); } … Read more…

Java-Extracting Character

Extracting Character The charAt( ) method provides the character at the specified index position. The starting value of the index in the case of a string is zero. For example, in the following program, the character at position 3 in the string “hajsof” is ‘s’. Thus, the str1.charAt(3) method will return the character ‘s’. Concat … Read more…

Java-String Concatenation

String Concatenation Java defines one operator for string object such as “+”, it is used to concatenate two string. For example, in the following program, the value of the variable ‘a’ and ‘b’ is being converted to a string that represents this value as a decimal digit character. This is prompted by the fact that it … Read more…