Q:

Adding parsed text into String

I was working on my first project which includes a website parser. I attempted to learn a little bit about parsers and stumbled across a library called "Jsoup" found here: 
http://jsoup.org/download
I then tried this code example which i found on a tutorial website: 
import java.io.IOException;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class HTMLParserExample1 {

  public static void main(String[] args) {

    Document doc;
    try {

        // need http protocol
        doc = Jsoup.connect("http://google.com").get();

        // get page title
        String title = doc.title();
        System.out.println("title : " + title);

        // get all links
        Elements links = doc.select("a[href]");
        for (Element link : links) {

            // get the value from href attribute
            System.out.println("\nlink : " + link.attr("href"));
            System.out.println("text : " + link.text());

        }

    } catch (IOException e) {
        e.printStackTrace();
    }

  }

}

The code worked well so i decided to attempt to combine it with the rest of my application (Which is a JFrame with a textbox inside it)
So what i attempted to do is putting what was put inside [code]System.out.println();[/code] inside a string. 
While doing this i was getting errors while i was trying to do it the following way:
s + "\nlink : " + link.attr("href");
s + "text : " + link.text();

I was getting errors and soon realised this wasnt the correct way of doing it, So i found the method String.concat and decided to use it.
After using this it still didnt work and i then also realised that what should be parsed also stopped being printed out with the System.out command.. 
Here is my current code:
import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class JParser {

    private String finishedParse;

     public static void JParser() {

         //String that should hold the finished parse
         String finishedParse = new String();

         //test string used to see if what the Netbeans IDE recomended me to do work
         String tester = new String();
         finishedParse = "";

    Document doc;
    try {

        //Need http protocol
        doc = Jsoup.connect("http://google.com").get();

        //Get page title
        String title = doc.title();
        System.out.println("title : " + title);

        //Get all links
        Elements links = doc.select("a[href]");
        for (Element link : links) {

            //Get the value from href attribute
            System.out.println("\nlink : " + link.attr("href"));
            System.out.println("text : " + link.text());
                        tester = finishedParse.concat("\nlink : " + link.attr("href"));
                        tester = finishedParse.concat("text : " + link.text());
                        tester = finishedParse.concat("\n");

        }

    } catch (IOException e) {
        e.printStackTrace();
                System.out.println(e);
    }
  }

     //The method i wish to call from my other class to get the parsed text returned.
     public String getParsedText(String parsedText){
         parsedText = finishedParse;
         return parsedText;
     }
}

The problem now is that what is supposed to get printed with the System.out command is not being printed out and i still havn't figured out how to get the parsed text into my String.
Im realy intrested in learning and i have a hard time finding what in my code is wrong. I did search the web for answears but had no sucess.
THE ERROR REMAINING IS THE FOLLOWING
The two System.out statements are not printing out anything to the console, It did work when i copied the code from the tutorial. Both of the codes is in the post above, Read and help me please.
The problem was that i called the class in a strange way, My best guess is that i was tired yesterday so my ignorance kicked in..

A:

Try this:
for (Element link : links) {

  // Get the value from href attribute
  System.out.println("\nlink : " + link.attr("href"));
  System.out.println("text : " + link.text());
  finishedParse = finishedParse.concat("\nlink : " + link.attr("href"));
  finishedParse = finishedParse.concat("text : " + link.text());
  finishedParse = finishedParse.concat("\n");

}

Notice that using concat() is exactly the same as using the + operator, the real problem was that you should update the string that's being used to concatenate the final answer. Even better, you should use a StringBuilder for this kind of job - it will be update in-place (whereas concat() returns a new string every time), so it's much more efficient.
StringBuilder sb = new StringBuilder();

for (Element link : links) {

  // Get the value from href attribute
  System.out.println("\nlink : " + link.attr("href"));
  System.out.println("text : " + link.text());
  sb.append("\nlink : " + link.attr("href"));
  sb.append("text : " + link.text());
  sb.append("\n");

}

String finishedParse = sb.toString();

