Multiple datatypes in linkedlist | Sololearn: Learn to code for FREE!

0

Multiple datatypes in linkedlist

How can we insert multiple data types to a linkedlist. I am encountering a WARNING message. https://code.sololearn.com/cVyyf22458rT/?ref=app

5/8/2021 12:34:02 PM

sid

5 Answers

New Answer

+1

*How can we insert multiple data types to a linkedlist* -> Pass `Object` as type parameter to list ctor. line 9: ``` LinkedList<Object> link=new LinkedList<>(); ``` *I am encountering a WARNING message.* -> `Integer(int)` ctor is deprecated and it's recommended to use factory method Integer.valueOf() for better performance. Same for other wrapper classed like Double, Character, Float So wherever you wrote Integer(someinthere) use Integer.valueOf(someinthere) or better yet, let java handle this with autoboxing. just write list.add(someinthere). Java 5 and above will automatically wrap primitives in respective wrapper classes. Sololearn is currently using Java 16 so it'll work fine. list.add(Integer.valueOf(10)) is same as list.add(10)

+1

🇮🇳Omkar🕉 Really appreciated.Stay safe

0

🇮🇳Omkar🕉 even we did that we get another warning Java uses unchecked or unsafe operations. recompile with -xlint:unchecked for details. (I have to specify the type of linked List). Any thoughts?

0

sid, Give link of your code

0

Ok. I see you made changes in same code. I told you to pass type parameter to LinkedList's constructor already. LinkedList<Object> list = new LinkedList<>();