Project Euler 22: Names scores Description of challenge:


  Using names.txt (right click and 'Save Link/Target As...'), a 46K text
  file containing over five-thousand first names, begin by sorting it
  into alphabetical order. Then working out the alphabetical value for
  each name, multiply this value by its alphabetical position in the
  list to obtain a name score.
  
  For example, when the list is sorted into alphabetical order, COLIN,
  which is worth \$3 + 15 + 12 + 9 + 14 = 53\$, is the 938th name in the
  list. So, COLIN would obtain a score of \$938 × 53 = 49714\$.
  
  What is the total of all the name scores in the file?


I quickly created a solution: it was fairly easy, but I am specifically concerned about the performance, which I am unsure of. What I do know is:


string.split(): \$O(n)\$
Arrays.sort(): \$O(n \log n)\$ Worst Case
Remaining code: \$O(nm)\$, where \$n\$ is the length, and \$m\$ is the average length of the names


The code is below:

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Arrays;

public class ProjectEuler22 {

    private static final String filePath = "names.txt";
    private static final int ASCII_VALUE_TO_INT = 64; // naming

    public static void main(String[] args) {
        long time = System.nanoTime();
        String[] names = readAllNames().split("\",\"");
        names[0] = names[0].substring(1);
        int length = names.length; // extra "
        names[length - 1] = names[length - 1].substring(0,
                names[length - 1].length()); // extra "
        Arrays.sort(names);
        int total = 0;
        for (int i = 0; i &lt; length; i++) {
            total += getValueOfName(names[i], i + 1);
        }
        time = System.nanoTime() - time;
        System.out.println("The result is: " + total + "\nTime taken (ns): "
                + time);
    }

    private static String readAllNames() {
        try (BufferedReader reader = new BufferedReader(
                new FileReader(filePath))) {
            return reader.readLine();
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * Gets the value of the given string. If there are characters other than
     * [A-Z], then it will ignore it. Note that the problem file only contains
     * names with all caps.
     * 
     * @param string
     *            the name to get the value of
     * @param i
     *            the index of the name
     * @return the value of the name
     */
    private static int getValueOfName(String string, int i) {
        char[] array = string.toCharArray();
        int sum = 0;
        for (char c : array) {
            if (Character.isUpperCase(c)) {
                sum += c - ASCII_VALUE_TO_INT;
            }
        }
        return sum * i;
    }

}


Output:


   The result is: 871198282
 Time taken (ns): 19757146


Time taken seems to be around 20_000_000 nanoseconds.

Specific concerns:


Is there a better way to solve this? (As said above)
Where it says the // naming comment, is the naming fine? Anywhere else where the naming is off?
Anything else?
Well, there's a potentially more efficient way:

Read the whole file into a byte-array (It's not even a measly 64K), thus avoiding any conversion overhead and most object-allocations, extract the start-indices of all the names, and sort them.

Is it equally nice? Probably not. And it will only speed it up by a constant factor, because more just isn't there to be had.
Anyway, measure it because while going down a level gives opportunities for optimization, it's easy to get it wrong.
If you don't want to go quite that far, here's an easy one: Strip the trailing " from the last name, and you can drop the test whether you actually have a letter in getValueOfName.
Getting to your constants name, that's atrocious. Because, you know, using a named constant for that at all is so bad.
You can simply use a character-literal: 'A'-1
You fail to close the file in readAllNames if newing the BufferedReader fails. Admittedly that's unlikely in such a small program, but anyway.
Also, why do you catch IOException there, but then return null which immediately causes a NPE in turn in main?