I want to know how I go through the list and I add the conditions to then add the items to another list copy the image of the exercise because I do not know how to ask otherwise!
I do not want anyone to do anything for free I just want help! If you do not want to do it you are not obligated! and sorry for not putting my code! is this:
public List consultarItemsFaltantes (int máximoxima) { List result = new ArrayList ();
for (ItemStock lista : this.items) {
if (lista.getCantidad() < cantidadMaxima) {
resultado.add(lista);
}
}
// otro modo
for (int i = 0; i < items.size(); i++) {
if (items.get(i).getCantidad() < cantidadMaxima) {
resultado.add(items.get(i));
}
}
return resultado;
}
I put in two ways because I do not know if either of them is correct! or if both are what is the most prolix! Thank you and sorry for ignoring the rules of how you work in this environment! nobody wants to make them work for free! Excuse me if I wasted valuable time!
In this example I work with a list of integers, but you can modify it for the type of needs list, and work with a burned data 5, but it could be entered by keyboard. I hope it helps you.
import java.util.*; public class recorridoLista { static List ItemStock;
@SuppressWarnings("rawtypes") public static void main(String[] args) {
ItemStock = new ArrayList(); ItemStock.add(5); ItemStock.add(6); ItemStock.add(4); ItemStock.add(7); ItemStock.add(4); ItemStock.add(2); ItemStock.add(1);Iterator iter = ItemStock.iterator(); System.out.print("<ItemStock original> "); while (iter.hasNext()){ System.out.print(iter.next()); } System.out.print("\n<ItemStock items Menores> "); int cantidadMaxima=5; //Puede ser cualquier parametro List<Integer> resultado = cunsultarItemsFaltantes(cantidadMaxima); //menores a 5 Iterator iter2 = resultado.iterator(); while (iter2.hasNext()){ System.out.print(iter2.next()); } } public static List<Integer> cunsultarItemsFaltantes(int cantidadMaxima){ List<Integer> aux = new ArrayList<Integer>(); for(Integer val : ItemStock) { if(val<cantidadMaxima){ aux.add(val); //Nueva lista } } return aux; }}