Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

List of Integer.

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...