imprimir ArrayList en una función aparte
Publicado por MARIANA (1 intervención) el 13/04/2005 09:12:01
holas
quisiera saber como puedo imprimir un ArrayList en otra funcion este es mi codigo (ESTAS FUNCIONES TENGO QUE LLAMARLAS EN LA PRINCIPAL QEU PARA MI ES OTRA CLASE COMO LO HAGO? )
public class persona {
private int codigo;
private String nombre;
private String genero;
private static Object miclase;
public persona(int code, String nom, String gen) {
codigo = code;
nombre =nom;
genero = gen;
}
// INGRESO LOS DATOS DE LA PERSONA
public static void llenar2(int canti)
{
int code=0;
String title="";
String gen="";
ArrayList miclase = new ArrayList();
for(int i = 0; i < canti; i ++){
try {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Ingrese la nombre ");
nom = br.readLine();
System.out.println("Ingrese el genero ");
gen = br.readLine();
}
catch (Exception e) {
e.printStackTrace();
}
persona m = new persona(code, nom, gen);
miclase.add(m);
}
// AQUI HACEMOS LA IMPRESION DIRECCTA PERO NO ME SIRBE
/* for( Iterator it = miclase.iterator(); it.hasNext(); ) {
persona x = (persona)it.next();
System.out.println(x.codigo + " : " + x.titulo + ":"+ x.genero);
}*/
}
//ESTA ES LA FUNCION QUE NECESITO HACER
public static void mostrar2 (){
.... (NO SE QUE FALLA)
for( Iterator it = miclase.iterator(); it.hasNext(); ) {
persona x = (persona)it.next();
System.out.println(x.codigo + " : " + x.titulo + ":"+ x.genero);
}
}
}
quisiera saber como puedo imprimir un ArrayList en otra funcion este es mi codigo (ESTAS FUNCIONES TENGO QUE LLAMARLAS EN LA PRINCIPAL QEU PARA MI ES OTRA CLASE COMO LO HAGO? )
public class persona {
private int codigo;
private String nombre;
private String genero;
private static Object miclase;
public persona(int code, String nom, String gen) {
codigo = code;
nombre =nom;
genero = gen;
}
// INGRESO LOS DATOS DE LA PERSONA
public static void llenar2(int canti)
{
int code=0;
String title="";
String gen="";
ArrayList miclase = new ArrayList();
for(int i = 0; i < canti; i ++){
try {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Ingrese la nombre ");
nom = br.readLine();
System.out.println("Ingrese el genero ");
gen = br.readLine();
}
catch (Exception e) {
e.printStackTrace();
}
persona m = new persona(code, nom, gen);
miclase.add(m);
}
// AQUI HACEMOS LA IMPRESION DIRECCTA PERO NO ME SIRBE
/* for( Iterator it = miclase.iterator(); it.hasNext(); ) {
persona x = (persona)it.next();
System.out.println(x.codigo + " : " + x.titulo + ":"+ x.genero);
}*/
}
//ESTA ES LA FUNCION QUE NECESITO HACER
public static void mostrar2 (){
.... (NO SE QUE FALLA)
for( Iterator it = miclase.iterator(); it.hasNext(); ) {
persona x = (persona)it.next();
System.out.println(x.codigo + " : " + x.titulo + ":"+ x.genero);
}
}
}
Valora esta pregunta


0