我试图从对象的ArrayList(.NET 1.1 Framework)中检索正确的值:
我有以下定义:
Public AlList As New ArrayList
Public Class ItemInfo
Public ItemNo As Int16
Public ItemType As String
Public Reports As Array
Public PDFs As Array
End Class
Run Code Online (Sandbox Code Playgroud)
form_load事件代码包含:
Dim AnItemObj As New ItemInfo
Run Code Online (Sandbox Code Playgroud)
然后循环包括:
AnItemObj.ItemNo = AFile.RecordId
AnItemObj.ItemType = temp
AlList.Add(AnItemObj)
Run Code Online (Sandbox Code Playgroud)
所以我现在应该有这些对象的ArrayList,但是如果我尝试检索数据:
MsgBox(AlList(5).ItemNo)
Run Code Online (Sandbox Code Playgroud)
我总是得到列表中最后一个值的ItemNo.
我错过了什么?
此代码循环遍历mysql表并打印出空/空字段.然而,它打印数组值和这样的键
Array (
[0] => Field "dob" on entry "1" is empty/null
[1] => Field "user_name" on entry "7" is empty/null
)
Run Code Online (Sandbox Code Playgroud)
我该如何打印这样的东西 field "dob" on entry "1" is empty/null
$sql = "SELECT * FROM userinfo";
$res = mysql_query($sql);
while ($row = mysql_fetch_array($res)) {
foreach($row as $key => $field) {
if(empty($field)) {
$emptyFields[] = sprintf('Field "%s" on entry "%d" is empty/null', $key, $row['userid']);
}
}
}
print_r($emptyFields);
Run Code Online (Sandbox Code Playgroud) 我的程序中有四列按钮.分配新按钮时,按钮在列之间移动.而不是声明4个单独的arraylists来存储按钮,有没有办法创建1个arraylists数组,所以我可以简单地通过数组itterate?
我试过了 List<JButton>[] lists = new ArrayList<JButton>[5];
但那不行.我错过了什么?
编辑:
for(int i = 0; i < 5; i++){
if(choiceList.getSelectedIndex() == i){
if(btnPersons[nameList.getSelectedIndex()].getX() == column[i]){
JOptionPane.showMessageDialog(null, "Error - Name already present in the column.","", 1);
}else{
for(int j = 0; j < 5; j++){
if(lists[j].get(i) != null){
lists[j].remove(btnPersons[nameList.getSelectedIndex()]);
}
}
lists[i].add(btnPersons[nameList.getSelectedIndex()]);
lists[i].get(i).setBounds(column[i], ROWS[i], 125, 20);
//reloadLocations();
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的代码.一旦选择了新列,它会检查按钮所在的列表并将其删除,然后将其添加到新列表中.但我的新问题是使用列表[i]将不再有效.Idk如何使用此声明正确遍历我的arraylists列表:
List<ArrayList<JButton>> lists = new ArrayList<ArrayList<JButton>>();
Run Code Online (Sandbox Code Playgroud) 我收到错误,无法找到解决方法.
我将一个int添加到ArrayList.
int n = 1;
ArrayList list = new ArrayList();
list.add( n );
Run Code Online (Sandbox Code Playgroud)
再往下,我试着把它放回另一个int:
grid[ y ][ x ] = list.get(0);
Run Code Online (Sandbox Code Playgroud)
我也试过这个:
grid[ y ][ x ] = (int) list.get(0);
Run Code Online (Sandbox Code Playgroud)
但它不起作用,我得到这个错误:
found : java.lang.Object
required: int
grid[ y ][ x ] = (int)list.get(0);
^
Run Code Online (Sandbox Code Playgroud)
我希望有一个人可以帮助我.
我刚开始学习使用HashMap并阅读java教程,但我遇到了麻烦.
我正在尝试更新HashMap中的List,但是我想获取该密钥的列表,是否有办法更新密钥的特定列表而不必制作... 5个不同的列表并更新它们?
HashMap<String, ArrayList<String>> mMap = new HashMap<String, ArrayList<String>>();
ArrayList<String> list = new ArrayList<String>();
mMap.put("A", list);
mMap.put("B", list);
mMap.put("C", list);
mMap.put("D", list);
Iterator iter = mMap.entrySet().iterator();
if (mMap.containsKey("A"))
{
Map.Entry mEntry = (Map.Entry) iter.next();
list.add("test");
mMap.put("A",list);
System.out.println(mEntry.getKey() + " : " + mEntry.getValue());
}
else if (mMap.containsKey("B"))
{
Map.Entry mEntry = (Map.Entry) iter.next();
list.add("entry");
mMap.put("B",list);
System.out.println(mEntry.getKey() + " : " + mEntry.getValue());
}
Run Code Online (Sandbox Code Playgroud) 正如我在python中所知道的,我可以将列表设置为一个唯一的列表,如:
In [12]: a=range(12)
In [13]: a.append(5)
In [14]: a.append(4)
In [15]: a.append(5)
In [16]: a
Out[16]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 5, 4, 5]
In [17]: set(a)
Out[17]: set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])
Run Code Online (Sandbox Code Playgroud)
它对某些场景非常有用,我只是想知道如何在javascript中,
我有一个方法setData(ArrayList<super> list),所以任何想要设置数据的人都可以拥有自己的实体,只需要从超类扩展.但是当他们调用时,他们setData如何将ArrayList转换为ArrayList?
现在我使用setData(new ArrayList(list)),但这不是一个好的解决方案.
任何人都可以告诉我如何转换或其他解决方案可以避免这个问题.非常感激!
我有一个ArrayList包含一些对象,例如User,每个对象都有一个name和password属性.如何仅删除User具有特定"名称" 的对象ArrayList?
我对Java很新,我对方法调用转换有疑问.
我已经创建了一个新类,它扩展了名为ListableList的ArrayList - 但这似乎不是问题所在.
问题是我有一个看起来像这样的方法
public static void printList(ListableList<Listable> list, String seperator){
for(Listable item : list){
System.out.println(seperator);
System.out.println(item.toList());
}
System.out.println(seperator);
}
Run Code Online (Sandbox Code Playgroud)
我这样称呼这个方法:
Output.printList(rules, "..");
Run Code Online (Sandbox Code Playgroud)
规则初始化为
rules = new ListableList<Rule>();
Run Code Online (Sandbox Code Playgroud)
而Rule实现了Listable.
当我尝试编译时,我得到:
required: ListableList<Listable>,String
found: ListableList<Rule>,String
reason: actual argument ListableList<Rule> cannot be converted to ListableList<Listable> by method invocation conversion
Run Code Online (Sandbox Code Playgroud)
从我所学到的,为什么这应该起作用?提前致谢:)
以下是如何创建的两种方法ArrayList:
List<String/*or other object*/> arrList = new ArrayList();//Imports List, ArrayList
ArrayList<String/*or other object*/> arrList = new ArrayList();//Imports just ArrayList
Run Code Online (Sandbox Code Playgroud)
有什么不同?应该使用哪种方法?