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

public class lowerf {
    
        public static void main(String args[]){  
        String a="BASICENGINNER";  
        String alower=a.toLowerCase();  
        System.out.println(alower);  
        }
}
toLowercase() in Java

Let’s run the code

Input Values

Output Values

Output Values

toUppercase()

Convert the string into upper case

Syntax

obj=obj.touppercase();

Example of toUppercase() in String method.

Input Value

public class lowerf {
    
        public static void main(String args[]){  
        String a="BASICENGINNER student";  
        String alower=a.toUpperCase();  
        System.out.println(alower);  
        }
}
toUppercase() in Java

Let’s Run the code

Input Values

Output Value

Output Values

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

public class lowerf {
    
        public static void main(String args[]){  
        String a="BASICENGINNER student"; 
        System.out.println("string length is: "+a.length()); 
    
        }
}
length() in Java

Let’s Run the code

Input Values

Output Value

Output Values

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

public class lowerf {
    
        public static void main(String args[]){  
        String a="Baiseengineer student"; 
        String replaceString=a.replace('n','a');
        System.out.println(replaceString); 
    
        }
}
replace() in Java

Let’s Run the code

Input Values

Output Value

Output Values

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

public class lowerf {
     
        public static void main(String args[]){  
        String s1="  basic enginner    ";  
        System.out.println(s1+"student");  
        System.out.println(s1.trim()+"student"); 
        } 
    
}
trim() in Java

Let’s Run the code

Input Values

Output Value

Output Values

charAt()

This function returns the given position character.

Syntax

obj.charAt(index);

Example of charAt() in String method

Input Value

public class lowerf {
     
      
        public static void main(String args[]){  
        String name="student";  
        char a=name.charAt(3);  
        System.out.println(a);  
        } 
}
charAt() In Java

Let’s Run the code

Input Values

Output Value

Output Values

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


Basic Engineer

Hey Readers! We have more than fifteen years of experience in Software Development, IoT, Telecom, Banking, Finance and Embedded domain. Currently we are actively working on Data Science, ML and AI with multiple market leaders worldwide. Happy Reading. Cheers!

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *