How to create an object in a utility class based on if statement in Java? (Or based on a particular string)
<p>I would have a string that is parsed into an array, as shown here:</p>

<pre><code>class Example extends ParentClass {
    private String[] array;

    public static Example parseString(String lineToParse) {
        array = lineToParse.split("\");
    }

    public ObjectType1() { // arguments: String, String, String
    }

    public ObjectType2() { // arguments: String, String, String, double, double
    }
}
</code></pre>

<p>What I'm wondering is could I do this?</p>

<pre><code>if (array[0].equals("Test")) {
     public ObjectType1()
}
</code></pre>

<p>Or is there a better way to do this?</p>

<p>I want to create various objects with different arguments each, and the first argument (<code>array[0]</code>) will be applicable to each object, so I was wondering if I could create objects within an <code>if</code> statement like this, or a <code>switch</code> (not sure if that would work either).</p>
