Breaking

Search

Wednesday, June 24, 2020

important methods in string class in java

Method in Strings Class

important methods in string class in java

The write a Java Program of Demonstrate the Concept of Method in StringsClass

Program Procedure Steps:


step 1: Define a class by name stringshandling and declare a main().

step 2: Declar and intialize Four instance Variable strings1 strings2
              strings3 strings4 type string.

step 3: Using Print() are length () and display the length of string1 variable
              stringslength();

step 4: Using concat() Concatinate two stringsand display result strings1 concat (strings2).

step 5: Using Char * t() Finding the Fourth Character in the stringsstr1 Charp(4);

step 6: Using indus of ()Finding the index of in the Stringsstr1 str1 index of ('e');

step 7: Using the lest index of() tinding the last occurnce of 'e' in a stringsstr1 str2 last index of ('e');

step 8: Invoking Eqvalue() we are going to check two stringsstr1 Equal (string3)

step 9: Invoking Equal Igone case ()we can check two strings and case can be different string
              Equal Ignore(string3)

step 10: Invoking replace () we can replace a character with another character in a
                stringsstr1 replace (e,E)

step 11: Invoking to upper case ()we can change a with stringsto operator strings1 to upper case();

step 12: Invoking to lower case()we can change the whole stringsto lower case stringslowcase();

 

Method in stringsclass program:

 

class StringHandling

{

public static void main (Stringsargs[])

{

Stringsstr1=new String("College name");

Stringsstr2=new String("Chennai");

Stringsstr3="College name";

Stringsstr4="Java program"

System.out.println("Strings1 is:"+str1);

System.out.println("Strings2 is:"+str2);

System.out.println("Strings3 is:"+str3);

System.out.println("Strings4 is:"+str4);

System.out.println("Length of the String-->"+str1+"str1.length());

System.out.println("Concatenation of STR1 and STR2 is:"+str1.concat(str2));

system.Out.Println("character AT THE Position 4 in strings is:"+strings 1.CharAt (4));

system.out.println("index of the letter in STR1 is:"+str1.indexof('e'));

system.Out.Println("last index of the letter in strings 1 is:"+strings 1.lastindexod ('e'));

system.Out.Println("result of Equals()With strings 1 and strings 3 is :"+strings 1.Equals (strings3));

system.Out.Println("result of Equal IgnoreCase with strings 1 and strings 3 is: "+ strings 1.EqualsIgnoreCase (strings 3));

system.Out.Println("replacing E with e With e in strings 1: "+ strings 1.replace ('e'  , 'E'));

System.out.println("converting STR1 characters into Upper Case:"+str1.toUpperCase());

System.out.println("Converting STR2 characters into Lower Case:" +str2.toLowerCase());

system.Out.Println("removing uwanted White Spaces in a strings: "+ strings 4.Trim ());

}

}

 

OUTPUT:

E:\method\java>javac StringHandling.java

E:\method\java>java StringHandling

 

Strings1 is:College name

Strings2 is:Chennai

Strings3 is:College name

Strings4 is:Java Program

Length of the String-->College name is:15

Concatenation of STR1 and STR2 is: College name chennai

Character at the position 4 in STR is:N

index of the letter in STR1 is:2

Last index of the letter in STR1 is:14

Result of equals()with STR1 and STR3 is :false

Result of equal ignoreCase with STR1 and STR3 is:true

Replacing E with e with e in STR1:CoLlEge NaMe

converting STR1 characters into Upper Case:COLLEGE NAME

Converting STR2 characters into Lower Case:chennai

Removing unwanted white spaces in a strings:Java Program

RESULT:

Thus the program successfully Executed.


No comments:

Post a Comment