//

Strings

Sequence of characters

Declaration

By string literal

String str = "java";

By new keyword

String str = new String("java");

Notes:

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

Leave a Reply

Your email address will not be published. Required fields are marked *