Skip to content

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

Description

@avivmu

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions