7 String Important Function

In this blog, we will see 7 String important function like length(), toUpperCase() , toLowerCase() , charAt() , trim() , replace() , concat().

Let’s see example and video on 7 String Important Function

 

class str2

{

                public static void main(String args[])

                {

                                String str1 = “Welcome in String Class”;

 

                                // How to find length of string ?

                                int len = str1.length();    // return int length value

                                System.out.println(“Length of ” + str1 + ” is ” + len); // Length = 23

 

                                // How to Convert String to UpperCase or LowerCase

                                System.out.println(“Upper Case : ” + str1.toUpperCase());

                                System.out.println(“Lower Case : ” + str1.toLowerCase());

 

                                // How to find character at any location… charAt()

                                char ch = str1.charAt(5);                // give 5th number character : W=0,e=1,l=2,c=3,o=4,m=5

                                System.out.println(“5th character = ” + ch); // m

 

// trim() – How to remove front and back side extra space?

String str2 = ”     Welcome in String   “;     // extra space…

System.out.println(str2);              // Display with space

                                System.out.println(str2.trim()); // Display without space

 

                                // How to replace character or string part in String -> replace function

                                System.out.println(str1.replace(‘e’,’o’));

 

                                // How to join to string using concat() and + operator

                                String str3 = “Hello”;

                                String str4 = “Java”;

                                System.out.println(str3 + str4);                 // using + operator

                                System.out.println(str3.concat(str4)); // using concat()

 

                                // Thank you for watching video

                                // Please subscribe or like videos

                }

}

Output:

Length of Welcome in String Class is 23

Upper  Case : WELCOME IN STRING CLASS

Lower Case : welcome in string class

5th character  = m

Welcome in String

Welcome in String

Wolcomo in String Class

HelloJava

HelloJava

 

 

Video available on YouTube.


[sbscrbr_form]

If you have any query on blog example, you can directly comment us or subscribe our website


Earn Money Online

1191total visits,4visits today


mayank

Hello, I am Maddy a Java blogger, trainer and developer

Related articles

1 Comment

  1. November 2, 2016 - 5:46 pm

    I like this website – its so usefull and helpfull

Leave a Reply

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

Your comments (*)

Name (*)

Your full name please.

Email address (*)

Used for gravatar.

Website

Link back if you want.

Enter Captcha Here :*

Reload Image