How to move the first word in a string to the end? [closed]

I wanna change INLET CENTRE STN BAY 1 to CENTRE STN BAY 1 INLET And this is my code:

public class TST {

    public static void main(String[] args) {
        String st = "INLET CENTRE STN BAY 1";
        search(st);
        System.out.println(st);
    }

    private static String search(String st) {
        String[] parts = st.split(" ", 2);
        String firstWord = parts[0];
        String rest = parts[1];
        return rest + " " + firstWord;
    }
}

But it seems doesn’t work, is there any other way to address this issue?

Answer

I would use a regex replacement here:

String input = "INLET CENTRE STN BAY 1";
String output = input.replaceAll("^(\S+) (.*)$", "$2 $1");
System.out.println(output);  // CENTRE STN BAY 1 INLET