Multiple datatypes in linkedlist | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

8th May 2021, 12:34 PM
sid
sid - avatar
5 Answers
+ 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)
8th May 2021, 1:07 PM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar
+ 1
🇮🇳Omkar🕉 Really appreciated.Stay safe
8th May 2021, 1:59 PM
sid
sid - avatar
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?
8th May 2021, 2:07 PM
sid
sid - avatar
0
sid, Give link of your code
8th May 2021, 2:25 PM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar
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<>();
8th May 2021, 2:28 PM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar