Reversing a domain name string in Java
StringTokenizer is an OK solution, but I think that String.split() would lead to a less verbose solution.

Here is a Java 8 solution that uses split():

public static String reverseDomainNameString(String s) {
    List&lt;String&gt; components = Arrays.asList(s.split("\\."));
    Collections.reverse(components);
    return String.join(".", components.toArray(new String[0]));
}


Without Java 8's String.join(), though, the solution would be more tedious.  Note that it might be a good idea to ensure that the string is non-empty, otherwise components[0] (or st.nextToken() in your original solution) would crash.

public static String reverse(String s) {
    if (s == null || s.isEmpty()) return s;
    String[] components = s.split("\\.");
    StringBuilder result = new StringBuilder(s.length());
    for (int i = components.length - 1; i &gt; 0; i--) {
        result.append(components[i]).append(".");
    }
    return result.append(components[0]).toString();
}