-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

2
  • 7
    Please go through the documentation of String#split method. It just requires a google search. Commented Oct 30, 2012 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! Commented Oct 30, 2012 at 19:26

1 Answer 1

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]); } } 
Sign up to request clarification or add additional context in comments.

1 Comment

So you look at the full name from the back ?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.