What is the difference between char and Character in Java?

前端 未结 4 866
失恋的感觉
失恋的感觉 2021-02-01 07:31

I need to know what is the difference between char and Character in Java because when I was making a java program, the char worked while the Character didn\'t work.

4条回答
  •  长发绾君心
    2021-02-01 08:01

    char is a primitive type that represents a single 16 bit Unicode character while Character is a wrapper class that allows us to use char primitive concept in OOP-kind of way.

    Example for char,

    char ch = 'a';
    

    Example of Character,

    Character.toUpperCase(ch);
    

    It converts 'a' to 'A'

提交回复
热议问题