Borrar dato de ArrayList
Publicado por Bill (5 intervenciones) el 13/12/2016 01:57:50
Hola a todos necesito ayuda para pasar a una lista un registro de objetos de un txt, y borrar a uno de los objetos accediendo a uno de sus atributos(su numero de referencia). pero no lo borra
Auxilio.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
ArrayList list=new ArrayList();
Iterator<Currante> i=list.iterator();
// Cargamos
Scanner s=new Scanner(new File("Arch.txt"));
while(s.hasNextLine()){
list.add(s.nextLine());
}
// Eliminamos el txt
File F=new File("Arch.txt");
F.delete();
try{
F.createNewFile();
}catch(IOException ioe){
System.out.println(" ioe");
}
// Solicitamos atributo
int g=Integer.ParseInt(JOptionPane.showInputDialog("Introduzca el numero del trabajador"));
// Borramos
while(i.hasNext()){
int h=i.next().getNum();
if(g==h){
i.remove();
}
}
Auxilio.
Valora esta pregunta
0