Is there a way to invoke a static method of a class using a string which has the name of the class?
<p>I have an array of strings containing names of classes. Is it possible to invoke the static methods of the actual class using the 'name of the class' in the string array.</p>

<pre><code>public class SortCompare {

    // There are classes called 'Insertion', 'Selection' and 'Shell' which have a 
    //   method called 'sort'
    private static String[] algorithm = {  "Insertion", "Selection", "Shell"};

    public static double timeTheRun(String alg, Comparable[] a) {

        for (int i = 0; i &lt; algorithm.length; i++)
            if (alg.equalsIgnoreCase(algorithm[i])) {
                Stopwatch timer = new Stopwatch();

                 // I want to invoke one of Insertion.sort(), Selection.sort()
                 // or Shell.sort() depending on the value of 'alg' here

                 break;
            }
                return timer.elapsedTime();
        }
</code></pre>

<p>I could forget about the array of strings and simple use a if-else block to invoke them.</p>

<pre><code>         if (alg.equals("Insertion"))
            Insertion.sort(a);
         else if (alg.equals("Selection"))
            Selection.sort(a);
         else if (alg.equals("Shell"))
            Shell.sort(a);
</code></pre>

<p>But I will keep implementing other sorts and variations of them in future and every time I will have to make changes in multiple places(The above if-else loop, the help message of my program). If the former approach is possible then I'll just have to insert an extra string to the array every time.</p>
