String is a sequence of characters.The class String
includes methods for examining individual characters of the sequence, for comparing strings, for searching strings, for extracting substrings, and for creating a copy of a string with all characters translated to uppercase or to lowercase.
Creating a String
There are two ways to create string in Java:
- String literal
String s = “Master of Computer Application”;
- Using new keyword
String s = new String (“Master of Computer Application”);
String Methods :-
charAt(int index)
Returns the
char
value at the specified index.compareTo(String anotherString)
Compares two strings .
equals(Object anObject) Compares this string to the specified object. |
concat(String str)
Concatenates the specified string to the end of this string.
contains(CharSequence s) Returns true if and only if this string contains the specified sequence of char values. length() Returns the length of this string. toLowerCase() Converts all of the characters in this String to lower case using the rules of the default locale. toUpperCase() Converts all of the characters in this String to upper case using the rules of the default locale.
replace(char oldChar, char newChar) Returns a new string resulting from replacing all occurrences of oldChar in this string with newChar .
|
0 Comments