You are here
Home > Java > Java String Class Useful Methods

Java String Class Useful Methods

Today I am gonna explain some useful methods of String class in Java. String class is very powerful class in java which provides many useful methods to manipulate string. Strings are object in java and it is not primitive datatype.

 Output

Length of str is 0
Length of str2 is 4
Length of str3 is 9str is empty: true
str2 is empty: false
Character at index 2 in str2 is s
‘T’ ‘e’ ‘s’ ‘t’Comparing String reference: false
Comparing String value: truecompstr1 and compstr3 are equal: true

TEST and test are equal: false
TEST and test are equal: true

compareTo Test with Testing: -3
compareTo Testing with Test: 3

Matching region: true

This is Testing starts with This: true
This is Testing starts with this: true

Index of ‘Test’ in ‘This is Testing’: 8
Index of ‘is’ in ‘This is Testing’: 2
Index of ‘is’ in ‘This is Testing’ after offset 3: 5

Last Index of ‘is’ in ‘This is Testing’: 5
Last Index of ‘is’ in ‘This is Testing’ before offset 4: 2

Substring of ‘This is Testing’ from index 3: s is Testing
Substring of ‘This is Testing’ from index 3 to 9: s is T
Subsequence of ‘This is Testing’ from index 3 to 9: s is T

Concatenation: This is Testing Added at last

Replacing ‘T’ with ‘P’ in ‘This is Testing’: Phis is Pesting
Replacing ‘is’ with ‘was’ in ‘This is Testing’: Thwas was Testing
Replacing first ‘is’ with ‘was’ in ‘This is Testing’: Thwas is Testing
Replacing each ‘is’ with ‘was’ in ‘This is Testing’: Thwas was Testing

‘This is Testing’ matches ‘This(.*)’ regex pattern: true
‘This is Testing’ matches ‘(.*)This’ regex pattern: false

This:is:test:are:you:ready after splitting
This is test are you ready
This:is:test:are:you:ready after splitting with limit 4
This is test are:you:ready

Upper to Lower: test
Lower to Upper: TEST

‘ With Space ‘ after trimming: ‘With Space’

ARRAY after converting to char array
‘A’ ‘R’ ‘R’ ‘A’ ‘Y’

Today is : 08 30,2015
45,24 45,2354850000
Number 1: 50 Number 2: 5.9

Interned: Interned String

Copied value from character array: CHARACTER
Copied subarray from character array: CHAR

Thank for visiting

Please share if you like it

Rajesh Kumar Sahanee
I am a passionate Java Developer and I like Computer Programming. I love to do some interesting experiments and listening music in my free time.
https://www.zatackcoder.com

Comments

zatackcoder
Top

  Â