Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A simpler splitting logic from name to first and last name #34

Open
avivmu opened this issue Oct 29, 2020 · 0 comments
Open

A simpler splitting logic from name to first and last name #34

avivmu opened this issue Oct 29, 2020 · 0 comments

Comments

@avivmu
Copy link
Contributor

avivmu commented Oct 29, 2020

The current code has the following method for splitting name to two:

public void setName(String wholeName) {

	String[] parts = wholeName.split(" ");
	this.firstName = parts[0];
	if (parts.length > 1) {
		this.lastName = StringUtils.arrayToDelimitedString(Arrays.copyOfRange(parts, 1, parts.length), " ");
	} else {
		this.lastName = "";
	}
}

IMHO, the same could be done without using arrays and 3rd party libraries:

public void setName(String wholeName) {
	final int i = wholeName.indexOf(" ");
	if (i > 0) {
		this.firstName = wholeName.substring(0, i);
		this.lastName = wholeName.substring(i + 1);
	} else {
		this.firstName = wholeName;
		this.lastName = "";
	}
}

Should I submit a PR for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant