我试图通过让listOfProducts和ittirating过它来过滤产品..要根据产品的价格过滤产品和打印将过滤
public List<Products> filterByPrice(int min,int max){
List<Products> listofproducts = products.retrieveProducts();
System.out.println(listofproducts +" size: " +listofproducts.size());
for (Products productsVar : listofproducts) {
if(productsVar.getPrice()>= min && productsVar.getPrice()<= max){
return listofproducts; //here how do i print the reduced listOfProducts
}
}
return null;
}
可能是其很容易的一个,但没有得到如何从列表中打印出降低过滤产品
感谢
至于你的代码,你有一个错误在这里。然而,如果'if'方法'filterByPrice'将返回一个没有任何过滤的列表 –