Sequence of characters
Declaration
By string literal
String str = "java";
By new keyword
String str = new String("java");
Notes:
- String objects are immutable in java.
- Whenever we manipulate a String object the new String is created rather than the original string being modified.
- What is String Constant Pool?
- Special storage in heap, which is used to store unique string objects.
- Why String is made immutable?
- Difference between String & String buffer
- String is immutable & StringBuffer is mutable
- intern() method?
- Ensures that String will get allocated in SCP
- Important Methods
- indexOf() : return index of I’st occurance of the character
- toCharArray(): used to form a new character array from the string
- charAt()-> returns char at the given index
- concat() -> passed string is appended to the end of the specified string
- replace() -> sued for replacing chaacters & substring in a string
- subString() -> used to extract a position of a string from given string
- split() -> sued to seperate the specifeid string depending on the expression passed
- compareTo() -> sued to compare 2 string slplabetically