Java – String and Character class

String class represents character string. For example:

String name = "Kronos";

Some String methods:

  • String.concat(string) – Concatenates the specified string to the end of this string.
  • String.subString(begin,end) – Returns a string that is a substring of this string. The substring begins at the specified begin and extends to the character at index end - 1
  • String.startsWith(string) – Tests if this string starts with the specified prefix.
  • String.length() – Returns the length of this string.
  • String.indexOf(char) – Returns the index within this string of the first occurrence of the specified character.
  • String.toLowerCase() – Converts all of the characters in this String to lower case using the rules of the default locale.
  • String.toUpperCase() – Converts all of the characters in this String to upper case using the rules of the default locale.

If you want to compare two String object use equal()

String and Character class, <span>Java – String and Character class</span>, KandZ
String and Character class, <span>Java – String and Character class</span>, KandZ

Read more about the String class here.


The Character class wraps a value of the primitive type char in an object. An object of type Character contains a single field whose type is char. All its methods are static.

Some methods:

  • Character.toUpperCase(ch) – Converts the character argument to uppercase using case mapping information from the UnicodeData file.
  • Character.toLowerCase(ch) – Converts the character argument to lowercase using case mapping information from the UnicodeData file.
  • Character.isUpperCase(ch) – Determines if the specified character is an uppercase character.
  • Character.isLowerCase(ch) – Determines if the specified character is a lowercase character.
  • Character.isWhiteSpace(ch) – Determines if the specified character is white space according to Java.
  • Character.isLetter(ch) – Determines if the specified character is a letter.
  • Character.isDigit(ch) – Determines if the specified character is a digit.

example:

String and Character class, <span>Java – String and Character class</span>, KandZ
String and Character class, <span>Java – String and Character class</span>, KandZ

Read more about Character class here.

THE END!!!

86400cookie-checkJava – String and Character classJava – String and Character class

Related posts

2 Thoughts to “Java – String and Character class

  1. […] Java – String and Character class […]

  2. […] Java – String and Character class […]

Comments are closed.