String Class In Java

0
163
String-Class-In-Java

 

What is String in Java?

String is basically an sequence of char values in Java. String is also an object in Java.

1 St way :  Creating the String objects using object creation process using new keyword.

2nd way : We can declare the string like other data types by declaring

String str = “qacreators”

Java String provides many methods to perform  operations like substring(), concat(), length(), equals(), replace(), split() etc.

  1. SubString() : SubString method in java will separate a part of String from the actual String and will store the separated String.

SubString Example : 

OUTPUT :

Java SubString Inbuilt Function

2. concat() : Concat method will append one string to another String. Second String will be concatenated at the end.

Example of Concat :

OUTPUT :

Java concatenate Inbuilt Function
3.length() : Length method will return total number of characters available in the String.

Example of Length:

OUTPUT :

Java length Inbuilt Function
4. equals() : Equals method will compare two Strings for their content. If both the String content are equal true value is returned, else false value is returned. Return type is boolean for equals method.

Example of Equals:

OUTPUT :

Java Equals Inbuilt Function

 

5. replace() : Replace method will return a String replacing all the old characters with new characters.

Example of Replace:

OUTPUT :

Java Replace Inbuilt Function
6.split() : Split method will split the String based on the regular expression that is passed and will return the char Array.

Example of Split:

OUTPUT :

Java split inbuilt Function

LEAVE A REPLY

Please enter your comment!
Please enter your name here