假设我有这个字符串 -
string = "AEIOU";
Run Code Online (Sandbox Code Playgroud)
我想将它转化成一个ArrayList<String>,其中每个字符是它自己的个体String内ArrayList<String>
[A, E, I, O, U]
Run Code Online (Sandbox Code Playgroud)
编辑:我不想转换ArrayList<Character>(是的,这非常简单,我在课堂上注意),但我想转换为ArrayList<String>.
我该怎么办?
我想从ArrayList中获取一些特定的数字随机值
final ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>();
for (int i = 0; i == 4; i++) {
index = random.nextInt(menuItems.size());
HashMap<String, String> getitem = menuItems.get(index);
System.out.println(getitem.get(KEY_NAME));
}
Run Code Online (Sandbox Code Playgroud)
什么都没打印出来.
如果我在循环外使用它,循环中的代码工作,但因为我需要多个值,我使用循环,它不起作用.
想象一下Java中的以下ArrayList:
ArrayList<Integer> u = new ArrayList<Integer>();
Run Code Online (Sandbox Code Playgroud)
我想知道在将新值添加为基本类型或包装类时是否存在差异:
u.add(new Integer(12));
u.add(12);
Run Code Online (Sandbox Code Playgroud)
提前致谢!
我在java中搜索保存数据的最佳方法.我有两个带ID和名称的ArrayLists.现在我希望它以最简单,最智能的方式保存.喜欢:
[index] [String ID] [String Name]
[1]["newID"]["Peter]
Run Code Online (Sandbox Code Playgroud)
它背后的想法是,例如,我有名称"彼得",所以我知道索引,所以我得到了ID.传入数据"彼得"得到索引1和ID"newID"
那么最好的方法是实现它.三维数组列表,矢量我不确定,谢谢:)
我有一个名为"Table"的类,它扩展了ArrayList.在这个类中,我有一个名为toArray()的方法.每当我编译我得到错误:"表中的toArray()无法在java.util.List中实现toArray()返回类型void与java.lang.Object []不兼容
这是Table类:
public class Table extends ArrayList<Row>
{
public ArrayList<String> applicants;
public String appArray[];
public String appArray2[] = {"hello", "world","hello","world","test"};
/**
* Constructor for objects of class Table
*/
public Table()
{
applicants = new ArrayList<String>();
}
public void addApplicant(String app)
{
applicants.add(app);
toArray();
}
public void toArray()
{
int x = applicants.size();
if (x == 0){ } else{
appArray=applicants.toArray(new String[x]);}
}
public void list() //Lists the arrayList
{
for (int i = 0; i<applicants.size(); i++)
{
System.out.println(applicants.get(i));
} …Run Code Online (Sandbox Code Playgroud) 嗨我的java代码有问题...
问题是在我的列表的添加(e)中:
List<Sms> listSms = new ArrayList<Sms>();
for(int i = 0; i < grupo.size(); i++){
Grupo group = new GrupoDao().carregaById(grupo.get(i),usuario.logado);
for(int j = 0; j < group.getContatos().size(); j++){
sms.setNumber(group.getContatos().get(j).getNumber());
listSms.add(sms);//Here he override all the list sms.number to last one added
}
}
Run Code Online (Sandbox Code Playgroud)
有谁能够帮我 ?
我有一个ArrayLists的HashMap用于值,但是当我添加ArrayLists时HashMap保持为空,然后当我尝试get()ArrayList时抛出NullPointerException.非常困惑.
Random rand = new Random();
HashMap<String,ArrayList<Integer>> hands = new HashMap<String,ArrayList<Integer>>();
HashMap<Integer, Boolean> deck = new HashMap<Integer, Boolean>();
for(int x=0;x<4;x++){
for(int y=0;y<4;y++){
hands.put(x+SUITS[x], new ArrayList<Integer>());
}
}
for(int x=0;x<4;x++){
for(int y=0;y<13;y++){
int randCard = rand.nextInt(52)+1;
if(!deck.containsKey(randCard)){
deck.put(randCard, true);
hands.get(x+cardSuit(randCard)).add(randCard);
}else y--;
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个SQL查询返回整数数组.
ArrayList<Integer> intArray = new ArrayList<>(44);
while (result.next()){
intArray.add(result.getInt("CNT")); // Insert the result into Java Array List
}
// Insert the result into Java Object
dc = new DCDataObj(
intArray.get(1), // Datacenter 1000
intArray.get(2), // Zone 1100
..................
)
Run Code Online (Sandbox Code Playgroud)
运行代码时出现此错误:
java.lang.IndexOutOfBoundsException: Index: 40, Size: 40
你能告诉我使用ArrayList时我的错误在哪里?
我有班级名单A:
public class lista {
int i;
String name;
public lista(int i, String name)
{
this.i = i;
this.name = name;
}
}
Run Code Online (Sandbox Code Playgroud)
我从这个类中创建了ArrayList.
public static ArrayList<lista> friends;
Run Code Online (Sandbox Code Playgroud)
添加一些日期:14 - 亚当2 - 约翰35 - 阿诺德74 - x 54 - x
我想获得IndexOf 74并将名称从x更改为Catrina.
怎么做?
friends.get(friends.indexOf(??)) = "catarina";
Run Code Online (Sandbox Code Playgroud) 如何从arraylist中过滤唯一对象.
List<LabelValue> uniqueCityListBasedState = new ArrayList<LabelValue>();
for (LabelValue city : cityListBasedState) {
if (!uniqueCityListBasedState.contains(city)) {
uniqueCityListBasedState.add(city);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的代码.但问题是我不需要过滤对象,而是过滤该对象内属性的值.在这种情况下,我需要排除具有该名称的对象.
那是 city.getName()