-1

Possible Duplicate:
How do I split a string with any whitespace chars as delimiters?

I need to split full name so I return just the surname.

For example F. J. Hill (we assume that last name is always after first name or after initials)

so this is what i got so far

public String getLastName(){
    String surname;
    surname = FullName.split;
}

but this doesn't work. Can i get some help please ? Dont really understand how split string works

Community
  • 1
  • 1
Tom
  • 41
  • 7
  • 7
    Please go through the documentation of `String#split` method. It just requires a google search. – Rohit Jain Oct 30 '12 at 19:24
  • Firstly, in Java you have to put parentheses (`()`) after a method name to call it. The last line of your method should be `surname = FullName.split([parameters]);`. And don't forget to return a value! – 11684 Oct 30 '12 at 19:26

1 Answers1

2

Can you see if this solves your answer?

public class Test {
    public static void main(String[] args) {
        String name = "F. J. Hill";
        String[] split = name.split(" ");
        int size = split.length - 1;
        System.out.println(split[size]);
    }
}