Java - Write code to return Last Word from a sentence

Requirements

Write code to return Last Word from a sentence

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String s = "this is a test";
        System.out.println(returnLastWord(s));
    }//w  ww .j  av  a2 s  .com

    public static String returnLastWord(String s) {
        String[] split = s.split(" ");
        return Cap(removeSpaces(split[split.length - 1]));
    }

    public static String Cap(String input) {
        return input.substring(0, 1).toUpperCase() + input.substring(1);
    }

    public static String removeSpaces(String s) {
        return s.replaceAll(" ", "");
    }
}

Related Exercise