Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java中如何从列表中获取特定列列表_Java_List - Fatal编程技术网

Java中如何从列表中获取特定列列表

Java中如何从列表中获取特定列列表,java,list,Java,List,我有某个表中的列表,我想从该列表中选择特定的列 名单来自 List<StockInwordBean> stockInwordList = siDaoImpl.getStockInwordBeans(); 注意:它是类型的简单数组列表 在这里,我只需要列的特定列表作为列表中的“itemName” 我试过了 List<String> col = new ArrayList<String>(); for(int i=0 ;i< stockInwordLis

我有某个表中的列表,我想从该列表中选择特定的列

名单来自

List<StockInwordBean> stockInwordList = siDaoImpl.getStockInwordBeans();
注意:它是类型的简单数组列表

在这里,我只需要列的特定列表作为列表中的“itemName”

我试过了

List<String>  col = new ArrayList<String>();
for(int i=0 ;i< stockInwordList.size();i++)
{
      col.add(stockInwordList.get(i).toString());
      System.out.println("col is.."+col.get(i));

}
所以,请帮我把名单列出来

itemName=666

itemName=121

itemName=1 . .


提前感谢。

您只是在循环包含StockInwordBean的列表,并使用toString()将对象转换为字符串。相反,您必须将每个对象的特定属性添加到不同的列表中

请尝试以下代码:

List<String>  col = new ArrayList<String>();
for(StockInwordBean si : stockInwordList ){
   col.add(si.getItemName());
}
List col=new ArrayList();
for(StockInwordBean si:stockInwordList){
col.add(si.getItemName());
}

您只是在循环包含StockInwordBean的列表,并使用toString()将对象转换为字符串。相反,您必须将每个对象的特定属性添加到不同的列表中

请尝试以下代码:

List<String>  col = new ArrayList<String>();
for(StockInwordBean si : stockInwordList ){
   col.add(si.getItemName());
}
List col=new ArrayList();
for(StockInwordBean si:stockInwordList){
col.add(si.getItemName());
}

您存储的是对象的tostring,而不是所需的值

getItemName是getter方法

请尝试下面的代码片段

List<String>  col = new ArrayList<String>();
for(int i=0 ;i< stockInwordList.size();i++)
{
      col.add(stockInwordList.get(i).getItemName());
      System.out.println("col is.."+col.get(i));

}
List col=new ArrayList();
对于(int i=0;i
您存储的是对象的tostring,而不是所需的值

getItemName是getter方法

请尝试下面的代码片段

List<String>  col = new ArrayList<String>();
for(int i=0 ;i< stockInwordList.size();i++)
{
      col.add(stockInwordList.get(i).getItemName());
      System.out.println("col is.."+col.get(i));

}
List col=new ArrayList();
对于(int i=0;i
但是这里我们必须在StockInwordBean类中为getItemName()编写函数,或者只是将变量公开,直接用作si.itemName而不是getItemName()。但是最好为这个变量做setter和getter,你能给我解释一下(StockInwordBean si:stockInwordList)和[si]变量的更多信息吗……请……我还不了解这个过程……它是java中的一个for-each循环。它意味着对于列表stockInwordList中的每个StockInwordBean。si是每个StockInwordBean对象的变量。但这里我们必须在StockInwordBean类中为getItemName()编写函数,或者只是将变量公开并直接用作si.itemName而不是getItemName()。但是最好为这个变量做setter和getter,你能给我解释一下(StockInwordBean si:stockInwordList)和[si]变量的更多信息吗……请……我还不了解这个过程……它是java中的一个for-each循环。它意味着对于列表stockInwordList中的每个StockInwordBean。si是每个StockInwordBean对象的变量。