How can I declare a private method in a public method in Java?
<p>Fairly new to Java, so I hope the wording makes sense.</p>

<p>I have some Java code that needs to be called a few times within a public method, how can I reuse that code by placing it inside the public method and calling it?</p>

<p>Maybe I am making things hard for myself, so here's the code sample.</p>

<pre><code>public static final String parseText( final String text )
{
    StringBuffer parsedText = new StringBuffer();

    private static void appendParsedText( String snippet )
    {
        if ( parsedText.length() &gt; 0 )
        {
            parsedText.append( ", " + snippet );
        }
        parsedText.append( snippet );
    }

    if ( text.contains( "string1" ) )
    {
        parsedText.appendParsedText("string1");
    }

    if ( text.contains( "string2" ) )
    {
        parsedText.appendParsedText("string2");
    }

    if ( text.contains( "string3" ) )
    {
        parsedText.appendParsedText("string3");
    }

    return parsedText.toString();
}
</code></pre>

<p>Although the code is invalid, hopefully it makes sense with what I'm trying to achieve. I know there's a <code>join()</code> method in Apache Commons <code>StringUtils</code> but it seems like overkill, this method is the only place where this needs to happen.</p>
