String is the class (pre-defined) provide by java for storing the string value. It means when we create an object of string class then we can store a string value as. It is immutable. String is a Group of characters is called string. If we store a string value using string class then the length of the string will be fix means no further amendment will happen in that string.
String Method in Java
toLowercase()
convert the string into lowercase
Syntax
obj2=obj1.toLowerCase();
Example of toLowercase() in String method
Input Values
toLowercase() in Javapublic class lowerf { public static void main(String args[]){ String a="BASICENGINNER"; String alower=a.toLowerCase(); System.out.println(alower); } }
Let’s run the code
Output Values
toUppercase()
Convert the string into upper case
Syntax
obj=obj.touppercase();
Example of toUppercase() in String method.
Input Value
toUppercase() in Javapublic class lowerf { public static void main(String args[]){ String a="BASICENGINNER student"; String alower=a.toUpperCase(); System.out.println(alower); } }
Let’s Run the code
Output Value
length()
This returns the length of the string including spaces. Length of the string means no. of characters
Syntax
int var=obj.length();
Example of length() in String method
Input Value
length() in Javapublic class lowerf { public static void main(String args[]){ String a="BASICENGINNER student"; System.out.println("string length is: "+a.length()); } }
Let’s Run the code
Output Value
replace()
This method replace all the occurrence of given character with new character
Syntax
obj2=obj1.replace(‘old’,’new’);
Example of replace() in String method
Input Value
replace() in Javapublic class lowerf { public static void main(String args[]){ String a="Baiseengineer student"; String replaceString=a.replace('n','a'); System.out.println(replaceString); } }
Let’s Run the code
Output Value
trim()
It removes the blank spaces from left and right side of the given string.
Syntax
obj2=obj1.trim();
Example of trim() in String method
Input Value
trim() in Javapublic class lowerf { public static void main(String args[]){ String s1=" basic enginner "; System.out.println(s1+"student"); System.out.println(s1.trim()+"student"); } }
Let’s Run the code
Output Value
charAt()
This function returns the given position character.
Syntax
obj.charAt(index);
Example of charAt() in String method
Input Value
charAt() In Javapublic class lowerf { public static void main(String args[]){ String name="student"; char a=name.charAt(3); System.out.println(a); } }
Let’s Run the code
Output Value
If you have any queries regarding this article or if I have missed something on this topic, please feel free to add in the comment down below for the audience. See you guys in another article.
To know more about JAVA Wikipedia please click here .
Stay Connected Stay Safe, Thank you
0 Comments