0

I know that char is a primitive type while Character is a class, but I'm confused on when to use which? Is there a good rule of thumb for this?

210312312
  • 45
  • 3
  • Related: https://stackoverflow.com/questions/5199359/why-do-people-still-use-primitive-types-in-java – Fureeish Aug 31 '20 at 19:09
  • Use `char` if you don't need an object type; use `Character` if you do need an object type. – khelwood Aug 31 '20 at 19:09
  • For example when using generics. You can't have a `List` but a `List` is valid. Also keep in mind that primitives can not be `null`, because they are not a reference type (i.e. `Object`s), on the other hand their wrapper classes can, because they *are* `Object`s – Lino Aug 31 '20 at 19:11

0 Answers0