0

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!

3
  • 1
    [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])); Commented Jan 4, 2013 at 3:32
  • @HovercraftFullOfEels If I extract the Strings from the array will it not be an array anymore? Commented Jan 4, 2013 at 3:35
  • @HovercraftFullOfEels And after trying that line of code, I get this error 'no suitable method found for toString(java.lang.String)' Commented Jan 4, 2013 at 3:39

1 Answer 1

2

I personally think, "String words[]" words should be defined as "String []", like in Java creating an array.but I'm not too skilled for JSoup.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.