Java的ArrayList的整数 [英] Java ArrayList for integers
本文介绍了Java的ArrayList的整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有我想加入到一个ArrayList来跟踪什么数字表明了值。
这些值是整数,所以我创建了一个ArrayList
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);
但我不能添加任何使用这种方法的ArrayList的。
它的工作原理,如果我使用字符串数组列表。我必须使它成为一个字符串数组,然后不知何故数组转换为整数?
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?
编辑:我还有一个问题。我想在列表中只能容纳3的值。我会怎么做呢?
I have another question. I'd like the list to only hold 3 values. How would I do so?
推荐答案
整数
列表。
List<Integer> list = new ArrayList<>();
int x = 5;
list.add(x);
这篇关于Java的ArrayList的整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文