0

I have some string stored in

String url="*/One Url/*"
Document doc = Jsoup.connect(url).get();
  Elements paragraphs = doc.select("td");
  for(Element p : paragraphs)
    System.out.println(p.text());

So in p.text() I have some strings. And the output is in several lines. Now is there is any way by which I can handle the output in string array. So that I can use the data in different place.

1
  • could you be more specific with the url example. Do you want each table data as a separate string ?? Commented Feb 14, 2014 at 5:19

1 Answer 1

1
List<String> text = new ArrayList<>();
for(Element p : paragraphs) {
    text.add(p.text());
}

Unfortunately this is the only way now - but Java 8 with lambda expressions is coming soon so this would become one-liner.

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

1 Comment

I think if the OP is able to use JSoup and enhanced for loop than he is certainly able to read this trivial code (but I agree with you, I should have put there at least one sentence).

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.