What are Strings in Java?
- A String is a Sequence of Characters. String is a class in java which is a non mutable(i.e which cannot a change),
- Creating a string object there are 2 ways
- String s =" Hello" (Creating string using Assignment operator)
- String s = new String("Hello") (Creating string similar to objects are created)
- new is operator in Java
- Some of the important methods of Strings are
- int length() - Returns the lenght of the string
- String concat(String str)- concatinates specified string
- String[] split(String regex)- returns splitted string matching regex
- String trim() -removes beginning and ending spaces of this string.
- String toLowerCase()- return string in lowercase
- String toUpperCase() - return string in uppercase
- boolean equals(String another) // CANNOT use '==' or '!=' to compare two Strings in Java
- char charAt(int index) // index from 0 to String's length - 1