Why are Character arrays not valid, but char arrays are, and why are Character lists valid, but char lists not? This probably has something to do with primitives vs objects, but can someone explain it more clearly?
Asked
Active
Viewed 53 times
-1
-
1"Why are Character arrays not valid"—Who says they are not? – khelwood Aug 31 '20 at 20:56
-
You are right on spot. `char` is a primitive type. `Character` is the object type. Google a bit about their difference and autoboxing. – Augusto Aug 31 '20 at 20:57
1 Answers
2
both char[]
and Character[]
are perfectly valid. When it comes to generics, though, (like those in List<T>
), the generic parameter must be a class and not a primitive, so you can only have List<Character>
.

Mureinik
- 297,002
- 52
- 306
- 350