int a = 1; char b = (char) a; System.out.println(b);
will print out the char with Unicode code point 1 (start-of-heading char, which isn’t printable; see this table: C0 Controls and Basic Latin, same as ASCII)
int a = '1'; char b = (char) a; System.out.println(b);
will print out the char with Unicode code point 49 (one corresponding to ‘1’)
If you want to convert a digit (0-9), you can add 48 to it and cast, or something like Character.forDigit(a, 10);
.
If you want to convert an int
seen as a Unicode code point, you can use Character.toChars(48)
for example.
Related Posts:
- How can I convert a char to int in Java? [duplicate]
- How do I convert a String to an int in Java?
- Java – Convert integer to string [duplicate]
- How to convert a char to a String?
- How to convert/parse from String to char in java?
- “Char cannot be dereferenced” error
- “Char cannot be dereferenced” error
- “int cannot be dereferenced” in Java
- Java JDK – possible lossy conversion from double to int
- How can I prevent java.lang.NumberFormatException: For input string: “N/A”?
- How do I limit the number of decimals printed for a double?
- How do I limit the number of decimals printed for a double?
- Illegal Escape Character “\”
- How to check if an int is a null
- How do I apply the for-each loop to every character in a String?
- Understanding the difference between null and ‘\u000’ in Java
- Understanding the difference between null and ‘\u000’ in Java
- How to check whether a int is not null or empty?
- What is the difference between Integer and int in Java?
- Java, Simplified check if int array contains int
- JAVA Variable declaration not allowed here
- Unclosed Character Literal error
- Java Array Sort descending?
- Determine if a String is an Integer in Java [duplicate]
- Convert boolean to int in Java
- How to Convert Int to Unsigned Byte and Back
- Java – Change int to ascii
- Java Not Greater than Or Equal to Operator for Char Type
- How do you create a dictionary in Java? [closed]
- How do I declare and initialize an array in Java?
- Convert list to array in Java [duplicate]
- Convert String to double in Java
- Initialization of an ArrayList in one line
- Is there a Heap in java?
- What’s the difference between map() and flatMap() methods in Java 8?
- How to split a String by space
- Java compile error: “reached end of file while parsing }”
- Double % formatting question for printf in Java
- in java what does the @ symbol mean?
- How to call a method in another class in Java?
- unreported exception java.io.FileNotFoundException; must be caught or declared to be thrown
- Error creating bean with name ‘entityManagerFactory’ defined in class path resource : Invocation of init method failed
- Java, “Variable name” cannot be resolved to a variable
- How to convert a Binary String to a base 10 integer in Java
- HashSet vs. ArrayList
- FIFO based Queue implementations?
- How to import a .cer certificate into a java keystore?
- Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: 0 error in Java
- How can I represent a range in Java?
- How to solve error: ‘;’ expected in Java?
- Making a Java Makefile
- Censored Words Condition
- Android java.lang.IllegalStateException: Could not execute method of the activity
- Java error: Comparison method violates its general contract
- “Cannot create generic array of ..” – how to create an Array of Map
? - javac: file not found: first.java Usage: javac
- Eclipse Java error: This selection cannot be launched and there are no recent launches
- align text center with android
- hat is the purpose of flush() in Java streams?
- How can I convert integer into float in Java?
- How can I avoid this Ant Build error?
- Java Comparator class to sort arrays
- (The Triangle class) Design a class named Triangle that extends GeometricObject
- Convert char array to a int number in C
- Cannot assign requested address using ServerSocket.socketBind
- Consider defining a bean of type ‘package’ in your configuration [Spring-Boot]
- Java – How to do floor division?
- Short form for Java if statement
- IntelliJ – Can’t start – “JAVA_HOME does not point to a valid JVM installation”
- Empty an array in Java / processing
- Class is not Abstract and does not Override error in Java
- hibernate properties not found
- Make a simple timer in Java
- How to switch scenes in JavaFX
- Corrupt jar file
- Replace a character at a specific index in a string?
- Error array dimension missing
- How to detect EOF in Java?
- Information about _JAVA_OPTIONS
- Two dimensional array list
- Must issue a STARTTLS command first
- How to convert a String to CharSequence?
- Aspect Ratio with 800×480
- How do I convert a String to a BigInteger?
- How to set JAVA_HOME in Linux for all users
- What is ‘PermSize’ in Java?
- Creating a Calendar using javafx
- A tool for calculating the big-O time complexity of Java code? [closed]
- How to print binary tree diagram in Java?
- Must qualify the allocation with an enclosing instance of type GeoLocation
- Unknown version of Tomcat was specified in Eclipse
- How to compare character ignoring case in primitive types
- How can I wait for 10 second without locking application UI in android [duplicate]
- Java error “Value of local variable is not used”
- Is there a way to end the program if statement is false?
- toring and Retrieving ArrayList values from hashmap
- Could not find or load main class with a Jar File
- “uses unchecked or unsafe operations” [duplicate]
- How do I enable index downloads in Eclipse for Maven dependency search?
- How to convert java.util.Date to java.sql.Date?