Professional Documents
Culture Documents
isLetter() :-
This function is used to check whether a given argument is an alphabet or not. It
returns a Boolean type value either true or false.
Character.isDigit () :-
This function returns a Boolean type value true if a given argument is a digit
otherwise, false.
boolean p=Character.isDigit('G');
Character.isLetterOrDigit() :-
This function returns true if the given argument is either a letter or a digit, false
otherwise.
boolean b=Character.isLetterOrDigit('A');
boolean b=Character.isLetterOrDigit('r');
It returns true as the given character 'I' is a letter. boolean
b=Character.isLetterOrDigit('9');
boolean b=Character.isLetterOrDigit(**');
It returns false as the given character *** is neither a letter nor a digit.
Character.is WhiteSpace() :-
This function can be used to check for existing blank or gap in a String. It will return a
boolean type value (i.e.: true) if the given argument is a white space (blank) and, false
otherwise
Character.isUpperCase() :-
This function will return true if the given argument is an upper case letter
otherwise false.
boolean p=Character.isUpperCase('A');
boolean p=Character.isUpperCase('g');
Character.isLowerCase() :-
This function will return true if the given argument is a false.
Syntax: boolean variable = Character is LowerCase(character);
Character.toUpperCase() :-
This function returns the given argument in upper case character. The give
remains same if it is already in upper case. It returns the same character if the character
used with the function is non-alphabet.
char c=Character.toUpperCase('a');
char c=Character.toUpperCase('G');
char c=Character.toUpperCase("?');
It will return the same character because the given character is non-
alphabet.
Character.toLowerCase() :-
This function returns the given argument in lower case character. The given
character remains same if it is already in lower case. It returns the same character if the
character used with the function is non-alphabet.
char c=Character.toLowerCase(***);
char x= 'A';
int n=(int)x;
It results it as 65
int i=98 ;
char c = (char) i;
STRING FUNCTIONS:-
length() :-
This function is used to return the length of a string (i.e., number of characters present
in the string). You must note that the length is an integer number. Hence, it returns an
integer value.
int k = str.length:
String s = "COMPUTER";
char c = s.charAt(3);
indexOf() :-
This function returns the index (i.e. position number of the string:
int n = s.indexOf 'P', Here, the value returned by the function is 3. Hence, n =3.
String s = "MALAYALAM”;
int n=s.indexOf (4, 'A'); This function will return the index of 'A' available in the string
after 4 Hence, n = 5.
String s = "COMPUTER”,
int n =s.index of (3, 'C'); It returns NULL as character 'C' is not available after 3rd index.
lastIndexOf() :-
This function is applied to find the index of last occurrence of a character in a String,
Syntax: int variable=String variable.lastIndexOf(character);
substring() :-
This function is used to extract a part of string (i.e., simultaneous characters from one
index to another)
As the return value of the function is string so, you must use a string variable which
contains the result.
String p = s.substring (3, 6); It returns a part of string from 3rd position to the 6th
position by excluding the character, which is available at 6th position. Hence, p results
in PUT.
toLowerCase() :-
This function returns the characters of the string in lower case letters. If any character is
already in lower case or the character is a special character then it remains same.
toUpperCase() :-
This function returns a string after converting all the characters in upper case letters. If
any character is already in upper case or the character is a special case character then
it remains same.
replace() :-
This function is used to replace a character by another character or to replace a String
by another String at all its occurrence in the given String,
to appear
String s = "MXLXYXLXM";
String p = s.replace (X', 'A'); Here, each character X of the string is replaced by 'A'.
Hence, the new string p results in "MALAYALAM". 2.
TL String p = s.replace ("green", "red"); Here, each sub string "green" of the given string
is replaced by "red": Hence, the new string p results in "The red bottle is in red bag".
concat() :-
This function is applied to concatenate join) two strings together.
String z = x.concat(y); Here, both the strings x and y will be joined together. Hence, z
results in "COMPUTERAPPLICATIONS".
Java language also uses an operator '+' to concatenate two or more strings together.
equals() :-
This function is used to compare two strings together to check whether they are identi or
not. It returns a Boolean type value true if both are same, false otherwise.
else
System.out.println("different"): The given program snippet displays a different message.
You must note that equals() function treats corresponding upper case and lower case
characters differently.
equalsignoreCase() :-
This function is also used to compare two strings to ensure whether both are identical or
not after ignoring the case (i.e., corresponding upper and lower case characters are
treated to be same). It also returns a boolean data as true or false. Syntax: boolean
variable = string variablel. equalsignoreCase(string variable2);
compareTo() :-
It is also a type of function which compares two strings. It not only checks the equality of
the strings but also checks whether a string is bigger or smaller than other or not
Here,
The function returns an integer value depending upon the condition you want to check
n<0, if string x is less than string y. In the above example, the variable n is assigned to a
negative value (ie: n = 16), which is difference between the ASCII value of first
character 'C' of the string "COMPUTER" and 'S' of the string "SCIENCE". It always
compares character by character between the corresponding positions between two
strings.
You must note that the comparisons are based on the order of the corresponding
characters of the strings but not on the basis of the length of strings.
trim() :-
This function is used to remove the blanks from either side of the string. Other blanks,
which are available in between the words, remain unchanged.
Syntax: String variablel = String variable trim(); eg. String s = "COMPUTER
APPLICATIONS":
String p = s.trim();
endswith() :-
This function is used to check whether a given string has specified suffix or not. It
returns a boolean type value true or false accordingly. Syntax: boolean b= string
variablel.endswith(string variable2);
startwith() :-
This function returns a boolean type value true
String b= "YOUR":
Boolean X- p.starts withchy It will refum xas false al string p does not start with
n=Integer, valueOf(s);
n=Long.parseLong(s); or,
n=Long.valueOf(s);
n=Float parseFloat(s); or
n=Float valueOf(s);
n=double.parse Double(s); or
n=Double valueOf(s);
Thus, the variable n results in 24.315467398 (without quotes).
s=Integer.toString(n);
Here, an integer type number (n=24), gets converted to a String. Hence, s= "24". Now,
you can't perform any mathematical operations with the variable's'.
s=Float.toString(n);
Here, a floating type number (n=24.35), gets converted to String. Hence, s= "24.35".
s=Double.toString(n);
Here, a double type number (n=24.3452781), gets converted to String. Hence, s=
"24.3452781".