Archive Pages Design$type=blogging

Java - Character Class



Normally, when we work with characters, we use primitive data types char.

Example:

char ch = 'a';

// Unicode for uppercase Greek omega character
char uniChar = '\u039A'; 

// an array of chars
char[] charArray ={ 'a', 'b', 'c', 'd', 'e' }; 
However in development, we come across situations where we need to use objects instead of primitive data types. In order to achieve this, Java provides wrapper class Character for primitive data type char.
The Character class offers a number of useful class (i.e., static) methods for manipulating characters. You can create a Character object with the Character constructor:
Character ch = new Character('a');
The Java compiler will also create a Character object for you under some circumstances. For example, if you pass a primitive char into a method that expects an object, the compiler automatically converts the char to a Character for you. This feature is called autoboxing or unboxing, if the conversion goes the other way.

Example:

// Here following primitive char 'a'
// is boxed into the Character object ch
Character ch = 'a';

// Here primitive 'x' is boxed for method test,
// return is unboxed to char 'c'
char c = test('x');

Escape Sequences:

A character preceded by a backslash (\) is an escape sequence and has special meaning to the compiler.
The newline character (\n) has been used frequently in this tutorial in System.out.println() statements to advance to the next line after the string is printed.
Following table shows the Java escape sequences:
Escape SequenceDescription
\tInserts a tab in the text at this point.
\bInserts a backspace in the text at this point.
\nInserts a newline in the text at this point.
\rInserts a carriage return in the text at this point.
\fInserts a form feed in the text at this point.
\'Inserts a single quote character in the text at this point.
\"Inserts a double quote character in the text at this point.
\\Inserts a backslash character in the text at this point.
When an escape sequence is encountered in a print statement, the compiler interprets it accordingly.

Example:

If you want to put quotes within quotes you must use the escape sequence, \", on the interior quotes:
public class Test {

   public static void main(String args[]) {
      System.out.println("She said \"Hello!\" to me.");
   }
}
This would produce the following result:
She said "Hello!" to me.

Character Methods:

Here is the list of the important instance methods that all the subclasses of the Character class implement:
SNMethods with Description
1isLetter()
Determines whether the specified char value is a letter.
2isDigit()
Determines whether the specified char value is a digit.
3isWhitespace()
Determines whether the specified char value is white space.
4isUpperCase()
Determines whether the specified char value is uppercase.
5isLowerCase()
Determines whether the specified char value is lowercase.
6toUpperCase()
Returns the uppercase form of the specified char value.
7toLowerCase()
Returns the lowercase form of the specified char value.
8toString()
Returns a String object representing the specified character valuethat is, a one-character string.
For a complete list of methods, please refer to the java.lang.Character API specification.

What is Next?

In the next section, we will be going through the String class in Java. You will be learning how to declare and use Strings efficiently as well as some of the important methods in the String class.

COMMENTS

Naziv

Classes Converter - Free Currency Java Java YouTube Tutorials JavaFX JavaFX Free Download
false
ltr
item
Java - codeNerd: Java - Character Class
Java - Character Class
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhq6wUeBZbdoy9_yt1bUj9d5BNqwosCdk0VzdLvUYgbHndM27CeTs4hSNXW1suPpca1xBuwAS-k4pOd2FPCMdJShbttXVjqoeivswpwGmtoWUO4MUfmuDaJRylD7FfGuVq1LJyK-IHFGJE/s640/java_Static_vs_Dynamic_Binding.jpg
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhq6wUeBZbdoy9_yt1bUj9d5BNqwosCdk0VzdLvUYgbHndM27CeTs4hSNXW1suPpca1xBuwAS-k4pOd2FPCMdJShbttXVjqoeivswpwGmtoWUO4MUfmuDaJRylD7FfGuVq1LJyK-IHFGJE/s72-c/java_Static_vs_Dynamic_Binding.jpg
Java - codeNerd
https://javacodenerd.blogspot.com/2015/11/java-character-class.html
https://javacodenerd.blogspot.com/
http://javacodenerd.blogspot.com/
http://javacodenerd.blogspot.com/2015/11/java-character-class.html
true
198707769637465533
UTF-8
Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago