Java – how do I do this?

I'm a beginner. I want to write java code in eclipse The program takes linkedlists of two integers (for example, a and b) and creates a LinkedList (for example, d), where each element is the sum of the elements in a and B However, I cannot add these two elements from a and B because they are objects

Example:

a=[3,4,6,7,8]
b=[4,3,5,2,1]
------
d=[7,13,12,11,1]

Solution

You need to use generics to tell the compiler that there are integers in the list

List<Integer> a = new LinkedList<Integer>();
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>