-3
LinkedList<char> PC=new LinkedList<char>(); 

getting this error message when tried to run.

Solution.java:5: error: unexpected type
    LinkedList<char> PC=new LinkedList<char>();    
           ^
   required: reference
   found:    char

Can anyone explain why we can create the link list of arrays, object, and string but not of character?

Bhaid Man
  • 1
  • 2

2 Answers2

1

Array is an object, when char is a primitive type. As generics support only non-primitive types, you can create LinkedList<Character> and autoboxing will take care of packing chars into Character class.

Przemysław Moskal
  • 3,551
  • 2
  • 12
  • 21
0

you can create a linked list of any Object. just not primitives. you can't create a linked list of char\int\long\etc....

yairo
  • 103
  • 6