I have this code that calls a file txt
, stores it in a ArrayList
, and finally unordered and sorts all the characters in it.
public static void main (String args []) throws IOException{
String linea = "PALABRA2.TXT";
ArrayList<String> archivoLista = new ArrayList<>();
try (BufferedReader br = new BufferedReader(new FileReader("Archivo.txt"))) {
while ((linea = br.readLine()) != null) {
System.out.println(linea);
archivoLista.add(linea); /* Agrega la Línea leída a la lista */
}
}
System.out.println("LISTA DESORDENADA: ");
Collections.shuffle(archivoLista); /* Modifica Orden*/
/* Imprimir en una sola línea */
for(String temp: archivoLista){
System.out.println(temp);
}
/* Ordenar nuevamente*/
System.out.println("LISTA ORDENADA: ");
Collections.sort(archivoLista);
for(String temp: archivoLista){
System.out.println(temp);
}
}
}
What I want is to improve the design of the code. Someone here advised me to divide each function into different classes.
I need the first one with the method main
to show the file txt
in a Arraylist
, the second one receives that List<String>
and messes it up, and finally the third one receives it and orders it again.
The issue is that I do not know how it is done so that the classes have as parameter the arrayList
of main
. And so perform ordering and messing up.