okay, so here it is the full code
public static ArrayList<String> procuraGeneroLiterario(String nome_escritor) throws IOException{
String link = "https://pt.wikipedia.org/wiki/" + nome_escritor;
String pesquisa ="";
ArrayList<String> GeneroLiterario = new ArrayList();
HttpRequestFunctions.httpRequest(link,pesquisa,"ESCRITORES.txt");
String GenLit_er0 = "<td scope=\"row\" style=\"vertical-align: top; text-align: left; font-weight:bold; padding:4px 4px 4px 0\">Gênero(s)</td>";
String GenLit_er = "<a href=\"/wiki/.+ title=\".+\">(.+)</a>";
String Genero = null;
Scanner ler = new Scanner(new FileInputStream("ESCRITORES.txt"));
Pattern p0 = Pattern.compile(GenLit_er0);
Pattern p = Pattern.compile(GenLit_er);
while (ler.hasNextLine()) {
String linha = ler.nextLine();
Matcher f = p0.matcher(linha);
if(f.find()){
//linha = ler.nextLine();
while(ler.hasNextLine()){
linha = ler.nextLine();
Matcher m = p.matcher(linha);
if(m.find()){
Genero = m.group(1);
if (Genero != null){
for(int i = 0; i < Genero.size(); i++){
GeneroLiterario.add(Genero);
break;
}
}
}
}
}
}
ler.close();
return GeneroLiterario;
}
my teacher now told me to do but only if GeneroLiterario is declared as an ArrayList.
System.out.println("LISTA DE GeneroLiterarios: " );
for (int i=0; i<this.GeneroLiterarios.size(); i++)
System.out.println(this.GeneroLiterarios.get(i));
I made a class and there the GeneroLiterario is a String. Do i have to change it to arraylist? cause the output will be an arraylist of strings. and right now the output is [].