Java - Character (char)

> Procedural Languages > Java

1 - About

character in java.

They are only manipulated in unicode because the Java platform stores character values using Unicode conventions.

Advertising

3 - Management

The Character class provides several methods for:

  • determining a character's category (lowercase letter, digit, etc.)
  • and for converting characters from uppercase to lowercase and vice versa.

Character information is based on the Unicode Standard, version 6.0.0 and is based on the data file.

4 - Syntax

4.1 - Init

Java uses an int (and not a hexadecimal) to represent an unicode character therefore the box drawing character U+2514 can be represented in java by:

(char) 9492

or better

((char) Integer.parseInt("2514", 16))

that you can get as a string

String.valueOf((char) Integer.parseInt("2514", 16))

but you may also use single quote

char c = '"';
Advertising

4.2 - Null

char c = '\u0000';
char d = 0;
if (c == d){
     System.out.println("They are the same");
}

4.3 - Array

4.3.1 - Contains

char[] endOfLineCharacters = {(char) 10, (char) 13};
String.valueOf(endOfLineCharacters).contains(String.valueOf((char) 10)));
boolean contains(char[] charArray, char c){
    boolean contains = false;
    for (char cA : charArray) {
       if (cA == c) {
          contains = true;
          break;
       }
    }
    return contains;
}

5 - Documentation / Reference

lang/java/character.txt · Last modified: 2019/11/13 19:16 by gerardnico