Java - ArrayList, Iterator...

 
Vista:

ArrayList, Iterator...

Publicado por funny (1 intervención) el 20/06/2005 11:34:45
Hola a todos!

Necesito hacer un ArrayList para mostrar por pantalla(jsp) la nomina de un determinado empleado; es decir la cantidad que cobra cada mes:

enero_____________500€
febrero___________500€
marzo____________600€
etc.

Sé que debo de hacerlo con un ArrayList y utilizar el Iterator pero no tengo ni idea de como se utilizan ni la sintaxis.

Agradecería que alguien me escribiera un pekeño ejemplo.

Muchas gracias por vuestro tiempo.

Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:ArrayList, Iterator...

Publicado por J Hilario (54 intervenciones) el 20/06/2005 17:23:17
Hola, pues mira, un ejemplo pekeño de impresion con el iterator es como se muestra abajo. El arraylist solo acepta objetos, por eso es que se guardan como objetos y se recuperan con un cast. Si quieres guardar la información del mes o más información, haz tu propia clase con la información que necesites y creas instancias para cada conjunto de valores

ArrayList a = new ArrayList();
a.add(new Double(500));
a.add(new Double(600));
a.add(new Double(700));

Iterator it = a.iterator();
while(it.hasNext())
System.out.println((Double) it.next());

Saludos...
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:ArrayList, Iterator...

Publicado por manuchao (1 intervención) el 09/03/2006 17:25:19
import java.util.*;

class ItemsListing {

private String item;

// Constructor with parameters. When each object
// is instantiated, or created, arguments must be
// provided so the object contains the required
// data.
public ItemsListing (String item) {

// The keyword this is necessary to prevent confusion
// over which object you are referring to when
// you instantiate multiple objects.

this.item = item;
}

// Method to convert the objects to Strings.

public String toString() {

String s = "Item: " + item ;

return s;
}
}

public class ArrayListItems {

/**
* @param args
* Autor:
* manuchao
*
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

// Creates an ArrayList to store each object, and
// adds each object with the add method and dot operator
// as well as with the arguments for each object.

ArrayList items = new ArrayList();
items.add(new ItemsListing("Snorkel"));
items.add(new ItemsListing("Diving Mask"));
items.add(new ItemsListing("6.5 mm Wet Suit"));
//mete los datos en un array
System.out.println(items);
// The ArrayList is then passed to an Iterator

Iterator iterateItems = items.iterator();

// while loops through each element of the ArrayList
// and prints the results
//me da el tamaño del array
int i=items.size();
System.out.println("el tmanayi"+i);
//modifico los campos del array indico pos
items.set(2,"Item: espau");



while (iterateItems.hasNext()) {
System.out.println(iterateItems.next());

}

}

}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:ArrayList, Iterator...

Publicado por joel j (1 intervención) el 07/12/2006 01:16:04
utyyutyu
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar