If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Enjoy an ad free experience by logging in. Not a member yet? Register.

I wouldn't suggest doing that. If you do, you will need to manually separate the built string from the stringbuilder (the space in particular) to break the first and last name apart. So what you would do is pull the indexOf the space, and then issue a delete giving it the location of the space index (from indexOf) followed by the length of the entire string builder.

Or you can just keep it in two array indexes instead. A String[2] is sufficient for the size required for first and last name. I don't see a reason to use a string builder here if there is intent to change one of the strings.

Why not just store them in a string array? Use a string builder if you want when you're ready to combine them.
Mm, looks like you may just want to ask for the one name though yeah? in which case you already have a string for the entirety. There's a dozen ways to do this both with and without the string builder, but most of it still stands. If you work directly on the string input instead of worrying about a stringbuilder, you can use split on a regex to give you a string array, or you can use the indexOf for the spaces and substring to pull it apart and separate the strings.
Stringbuilder will work pretty much the same way, target where the space is with the .indexOf(" ") check, and then use delete/append, substring or replace to just do parts of the string.