Good evening, my question is how can I get the data that contains an ArrayList and when I get it I can insert it in a parameterized constructor of 4 parameters that are String, String, String, int ?. The class is Magazine with those 4 parameters, and inside the ArrayList I have the data that I have taken from a file, because when I have the data in the arrayList what I want every 4 positions of the array to create a new Journal with its data passing it through Parameters, but always I only get one. This is my code: '
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
public class PruebaLeerFicheroNuevo {
private static File fichero = new File("./fichero");
private static FileReader fr;
private static BufferedReader br;
private static ArrayList<Publicacion> publicaciones = new ArrayList<Publicacion>();
public static Publicacion nueva Publicacion;
public static void main(String[] args) {
try {
fr = new FileReader(fichero);
br = new BufferedReader(fr);
String palabra;
ArrayList<String> centinela = new ArrayList<String>();
while ((palabra = br.readLine()) != null) {
centinela.add(palabra);
}
// System.out.println("DATOS DE CENTINELA: " + centinela.toString());
ArrayList<Publicacion> mo = new ArrayList<Publicacion>();
for (int i = 4; i < centinela.size(); i++) {
String nombre = centinela.get(0);
String autor = centinela.get(1);
String materia = centinela.get(2);
int numero = Integer.parseInt(centinela.get(3));
nuevaPublicacion = new Revista(nombre, autor, materia, numero);
publicaciones.add(nuevaPublicacion);
}
br.close();
// MOSTRAMOS LOS DATOS DE publicaciones
for (int i = 0; i < publicaciones.size(); i++) {
Publicacion ver = publicaciones.get(i);
if (ver instanceof Revista) {
System.out.println("DATOS ver: ");
System.out.println(ver.toString());
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
} '