Home >Java >javaTutorial >Detailed explanation of the differences between Character and char methods
Today I suddenly need to use a Character. When using HashMap
HashMap< Integer, Character> map=new HashMap<Integer,Character>(); This can be used, but when defined as:
HashMap<Integer, char> map=new HashMap<Integer,char>(); In this case, problems will occur, so After checking the difference, I learned that when I was learning Java, I learned the English version, but I didn't learn it well, so now I can only make up for it slowly.
Character is a wrapper class for char, just like Integer and int, and Long and long.
Character is a wrapper class for char. Note that it is a class that provides many methods.
Packaging classes and basic types can be automatically converted. This is a new feature of jdk1.5 (5.0), called automatic sealing and automatic unblocking
That is:
## Example 1:
char ch='a';
Character ch1=ch;//Automatic sealing
Character c=new Character(a);
##char c1=c;//Automatically unblock
int t=10;
##Integer t1=t;//Automatic sealing
Integer t=new Integer(10);int t1=t//Automatically unblock
##[Related recommendations]
1. Free Java video tutorial
2. Detailed explanation of the Character class in Java
3.About the instance analysis of the packaging class Character
4.About the usage analysis of the Character class
5.Character class Detailed explanation of examples
The above is the detailed content of Detailed explanation of the differences between Character and char methods. For more information, please follow other related articles on the PHP Chinese website!