Since I'm a beginner I have no clue about the following problem, I've did hours of research but nothing could help me.
I have declared a static string which will be assigned in a for loop, later the string get's printed out in the console but it doesn't contain the full context.
import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
public class dothework {
static String info;
public void scrapeinfo() throws IOException {
Document doc = Jsoup.connect("html").get();
Elements el_name = doc.select(".champ-name");
Elements el_speed = doc.select(".speed");
Elements el_altitude = doc.select(".altitude");
el_name.size();
el_speed.size();
el_altitude.size();
for(int i = 0; i < 5; i++) {
String name = el_name.get(i).text();
String speed = el_speed.get(i).text();
String altitude = el_altitude.get(i).text();
String tempinfo = (name+": "+speed+" ("+altitude+")");
System.out.println(tempinfo);
info = tempinfo;
}
}
public void printinfo() {
System.out.println(info);
}
}
While System.out.println(tempinfo);
prints out the full information of 5 rows each containing name, speed and altitude the other System.out.println(info);
prints out just one row with name, speed and altitude. So the problem is that the strings differ even though I equalized them here:info = tempinfo;
. I guess that has something to do with the for-loop and/or with the modifier but I can't figure it out. Please help me.