Ver Mensaje Individual
  #1 (permalink)  
Antiguo 20/03/2013, 03:43
hextrem
 
Fecha de Ingreso: febrero-2013
Mensajes: 21
Antigüedad: 11 años, 2 meses
Puntos: 0
Exclamación contar las veces que se repite en un arraylist

Buenas haber si me podeis ayudar por favor, necesito recuperar las veces que se repite un elemento en un array list pero que solo muestre una vez el elemento. lo que tengo es esto
Código Javascript:
Ver original
  1. HttpSession sesion = request.getSession();
  2.          ArrayList<apoyo> detalle  = (ArrayList<apoyo>) sesion.getAttribute("carrito");
  3.          if (detalle!=null){
  4.          
  5.          
  6.           for(int i = 0;i<detalle.size();i++){
  7.               int unidades=0;
  8.              apoyo e = detalle.get(i);
  9.              for (int l = i;l<detalle.size();l++){
  10.              apoyo a = detalle.get(l);
  11.              if(e.getProducto().equals(a.getProducto())){
  12.                id = bd.idproducto(e.getProducto());  
  13.                unidades++;
  14.                        }
  15.              }
  16.            
  17.              int cantidadtotal = detalle.size();
  18.          
  19.          
  20.          String passwordcliente = sesion.getAttribute("pass").toString();
  21.          System.err.println("id "+id);
  22.          System.err.println(passwordcliente);
  23.          System.err.println("ct "+cantidadtotal);
  24.          System.err.println("unidades "+unidades);
  25.          /*bd.añadir(id, passwordcliente, unidades, cantidadtotal);*/
  26.          
  27.          id=0;
  28.          
  29.           }


Con esto me lo cuenta pero me aparece algo asi;
SEVERE: id 4
SEVERE: ana
SEVERE: ct 3
SEVERE: unidades 1
SEVERE: id 16
SEVERE: ana
SEVERE: ct 3
SEVERE: unidades 2
SEVERE: id 16
SEVERE: ana
SEVERE: ct 3
SEVERE: unidades 1

y solo quiero que me salga una vez lo de id 16 con unidades 2.
Gracias