Foros del Web » Programación para mayores de 30 ;) » Java »

[SOLUCIONADO] problema arraylists

Estas en el tema de problema arraylists en el foro de Java en Foros del Web. tengo un array que me gustaria que fuera de el porte de el usuario quiera para llenar los datos e imprimirlos al final lo unico ...
  #1 (permalink)  
Antiguo 22/05/2013, 10:04
 
Fecha de Ingreso: noviembre-2012
Ubicación: santiago
Mensajes: 23
Antigüedad: 11 años, 5 meses
Puntos: 0
problema arraylists

tengo un array que me gustaria que fuera de el porte de el usuario quiera para llenar los datos e imprimirlos al final
lo unico que me funciona pero me tira un error al final de mostrar los datos, una es la vista y la otra los datos si me pueden ayudar

Código Java:
Ver original
  1. */
  2. package clsarreglo;
  3.  
  4. import java.util.ArrayList;
  5.  
  6. /**
  7.  *
  8.  * @author Alumno
  9.  */
  10. public class clsPersona {
  11.     private String nombre;
  12.     private String apellido;
  13.     private String telefono;
  14.  
  15.     public String getApellido() {
  16.         return apellido;
  17.     }
  18.  
  19.     public void setApellido(String apellido) {
  20.         this.apellido = apellido;
  21.     }
  22.  
  23.     public String getNombre() {
  24.         return nombre;
  25.     }
  26.  
  27.     public void setNombre(String nombre) {
  28.         this.nombre = nombre;
  29.     }
  30.  
  31.     public String getTelefono() {
  32.         return telefono;
  33.     }
  34.  
  35.     public void setTelefono(String telefono) {
  36.         this.telefono = telefono;
  37.     }
  38.       ArrayList<String> objarray=new ArrayList();
  39.     public void clsingreso(int pos,String nombre,String apellido){
  40.              
  41.                  objarray.add(pos,nombre);
  42.                  objarray.add(pos,apellido);
  43.  
  44.                          
  45.     }
  46.    
  47.      public void clsmostrar(){
  48.                 for (int j=0;j<=objarray.size();j++)
  49.              {
  50.                
  51.                
  52.                 System.out.println("que valor es :"+j+ objarray.get(j));
  53.              }
  54.              
  55. }
  56. }


Código Java:
Ver original
  1. */
  2. package clsarreglo;
  3.  
  4. import java.io.BufferedReader;
  5. import java.io.IOException;
  6. import java.io.InputStreamReader;
  7. import java.util.ArrayList;
  8.  
  9. /**
  10.  *
  11.  * @author Alumno
  12.  */
  13. public class Clsarreglo {
  14.  
  15.     /**
  16.      * @param args the command line arguments
  17.      */
  18.     public static void main(String[] args) throws IOException {
  19.         // TODO code application logic here
  20.        
  21.         BufferedReader obj = new BufferedReader( new InputStreamReader (System.in)) ;
  22.        
  23.  
  24.             clsPersona objPersona=new clsPersona();
  25.             System.out.println("Cuantos quiere ingresar");
  26.             int valor =Integer.parseInt(obj.readLine());
  27.              for (int i=0;i<valor;i++)
  28.              {
  29.                  System.out.println("ingrese nombre"+(i+1));
  30.                  objPersona.setNombre(obj.readLine());
  31.                  System.out.println("ingrese apellido"+(i+1));
  32.                  objPersona.setApellido(obj.readLine());
  33.                  objPersona.clsingreso(i, objPersona.getNombre(), objPersona.getApellido());
  34.              
  35.                  if (i==valor-1)
  36.                  {
  37.                        objPersona.clsmostrar();
  38.        
  39.                 }    
  40.        
  41.            }
  42.     }}
  #2 (permalink)  
Antiguo 22/05/2013, 10:24
 
Fecha de Ingreso: noviembre-2012
Ubicación: santiago
Mensajes: 23
Antigüedad: 11 años, 5 meses
Puntos: 0
Respuesta: problema arraylists

public void clsmostrar(){
for(String element: objarray){
System.out.println(element);
}




}

solucionado :D

Etiquetas: string
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 18:14.