Java string function program
In java, objects of String are immutable which means a constant and cannot be changed once created. so, in technical terms, the basic Java String is basically an array of characters.
import java.io.*; class TenString { public static void main(String args[]) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter the String: "); String str =br.readLine(); System.out.println("Char at 3rd Position: "+str.charAt(2)); System.out.println("Index of u: "+str.indexOf('u')); System.out.println("Length of String: "+str.length()); System.out.println("Substring: "+str.substring(3)); System.out.println("String in lower case: "+str.toLowerCase()); System.out.println("String in upper case: "+str.toUpperCase()); System.out.println("After removing Whitespaces: "+str.trim()); String str1="www."; String s1 = String.valueOf(str1); System.out.println("After adding www. in Starting of the string: "+s1+str); System.out.println("Check String is equals to the EDUNEWS: "+str.equalsIgnoreCase("EDUNEWS")); System.out.println("After replacing e with a: "+str.replace('e','a')); } }
Program Output:
Enter the String: edunews Char at 3rd Position: u Index of u: 3 Length of String: 7 Substring: news String in lower case: edunews String in upper case: EDUNEWS After removing Whitespace: edunews After adding www. in Starting of the string: www.edunews Check String is equals to the EDUNEWS: true After replacing e with a: adunews
I hope this post helps you to understand the “Java string functions” and its implementation in Java programming language.
Keep coding 🙂