so I am grabbing a BIG list of elements using JSoup from a page. When I say big, I mean like a few hundred elements. I know that the elements are there because I converted them all to one huge string and they were all listed. Now what I need to do is put them into an array so I can process them 1 by 1. Here is my current code:
public static String [] grabWordList(String ending) throws IOException, InterruptedException{
Document doc = Jsoup.connect("http://site.com/").get();
Elements links = doc.getElementsByClass("defLink"); //Get words from site
String s[] = new String[links.size()]; //Create an array
int i = 0;
for(Element el : links){ //Attempt to put them into an array using this loop of blindly coppy and pasted code (I know, HORRIBLE Idea, I dont usually do that, but I am lost)
s[i++] = el.attr("links");
}
return s;
}
When I do this, I use this code to attempt to grab the array and print it:
String words[] = Methods.grabWordList("in");
for(int j=0; j < words.length; j++){
System.out.println(words[j]);
}
When running this code, all that prints is [Ljava.lang.String;@6201dbc
Im hoping that someone can help. Thanks!
[Ljava.lang.String;@...means you're trying to use an array of String where you should be using a String. You will want to extract the Strings from that array before adding. e.g.,System.out.println(java.util.Arrays.toString(words[j]));