Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
844 views
in Technique[技术] by (71.8m points)

arrays - Java ArrayList for integers

I have values that I'd like to add into an ArrayList to keep track of what numbers have shown up. The values are integers so I created an ArrayList;

ArrayList<Integer[]> list = new ArrayList<>();
int x = 5
list.add(x);

But I'm unable to add anything to the ArrayList using this method. It works if I use Strings for the array list. Would I have to make it a String array and then somehow convert the array to integers?

EDIT: I have another question. I'd like the list to only hold 3 values. How would I do so?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

List of Integer.

List<Integer> list = new ArrayList<>();
int x = 5;
list.add(x);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...