0% found this document useful (0 votes)
10 views2 pages

String Methods and Operations (1)

Uploaded by

Zaid Z.Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

String Methods and Operations (1)

Uploaded by

Zaid Z.Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Java String Class Methods and Operations:

1. String Class Methods:


-------------------------
- length()
- charAt(int index)
- substring(int beginIndex)
- substring(int beginIndex, int endIndex)
- contains(CharSequence s)
- equals(Object another)
- equalsIgnoreCase(String another)
- isEmpty()
- concat(String str)
- replace(char old, char new)
- replaceAll(String regex, String replacement)
- replaceFirst(String regex, String replacement)
- split(String regex)
- indexOf(String str)
- lastIndexOf(String str)
- toLowerCase()
- toUpperCase()
- trim()
- startsWith(String prefix)
- endsWith(String suffix)
- valueOf(primitive types or objects)
- matches(String regex)
- compareTo(String anotherString)
- compareToIgnoreCase(String str)

2. String Operations:
----------------------
- String concatenation using + and concat()
- String comparison: equals(), ==, compareTo()
- Substring extraction: substring()
- Searching in a string: indexOf(), lastIndexOf()
- Pattern matching: matches(), contains()
- Changing case: toUpperCase(), toLowerCase()
- Replacing characters: replace(), replaceAll()
- Trimming whitespaces: trim()
- Splitting strings: split()

3. StringBuffer Class Methods:


-------------------------------
- append(String str)
- insert(int offset, String str)
- replace(int start, int end, String str)
- delete(int start, int end)
- reverse()
- capacity()
- ensureCapacity(int minimumCapacity)
- setLength(int newLength)
- charAt(int index)
- setCharAt(int index, char ch)
- toString()
4. StringBuilder Class Methods (Same as StringBuffer):
-------------------------------------------------------
- append(String str)
- insert(int offset, String str)
- replace(int start, int end, String str)
- delete(int start, int end)
- reverse()
- capacity()
- ensureCapacity(int minimumCapacity)
- setLength(int newLength)
- charAt(int index)
- setCharAt(int index, char ch)
- toString()

Note: StringBuffer is synchronized (thread-safe), StringBuilder is not.

You might also like