Using the command .clear
of java.util.ArrayList;
the command resets the array of my graph object also but I just wanted it to delete arraylist sucs, follow the code:
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
public class PERT {
private static Scanner scanner2;
public static void main(String[] args) throws FileNotFoundException{
File file = new File ("Arquivos/entrada.txt");
String aresta = "";
int tempo = 0;
int i = 0;
scanner2 = new Scanner(file);
Scanner scanner = scanner2.useDelimiter("|");
ArrayList<Aresta> grafo = new ArrayList<Aresta>();
ArrayList<String> sucs = new ArrayList<String>();
while(scanner.hasNext()){
if(scanner.hasNext()){
aresta = scanner.next();
scanner.next();
tempo = scanner.nextInt();
scanner.next();
Aresta adc = new Aresta(aresta, null, null, tempo);
grafo.add(adc);
while(scanner.hasNext()){
String tmp = scanner.next();
if(tmp.equals("/")){
if(scanner.hasNextLine())
scanner.nextLine();
break;
}else{
sucs.add(tmp);
}
}
}
grafo.get(i).setSucessores(sucs);
sucs.clear();
i++;
}
for (i = 0; i < grafo.size(); i++) {
System.out.println(grafo.get(i).getAresta());
System.out.println(grafo.get(i).getTempo());
System.out.println(grafo.get(i).getSucessores());
}
scanner.close();
}
}