I have the class Racer :
public class Racer {
private String name;
private String team;
private String result;
public Racer(String name, String team) {
this.name = name;
this.team = team;
}
@Override
public String toString() {
return "Racer{" +
"name='" + name + '\'' +
", team='" + team + '\'' +
", result='" + result + '\'' +
'}';
}}
Then, I tried to create racer of this class in another Class :
public class RacerList {
public void createListOfRacers() {
Racer Kevin = createRacer("KMH_Kevin Magnussen_HAAS FERRARI");
}
And such methods to help creating racer :
private Racer createRacer(String line) {
return new Racer(extractNameOfTheRacer(line), extractTeamOfTheRacer(line));
}
private String extractNameOfTheRacer(String line) {
return line.substring(line.indexOf('_' + 1), line.lastIndexOf('_'));
}
private String extractTeamOfTheRacer(String line) {
return line.substring(line.lastIndexOf('_' + 1));
}
}
I received indicated Error here :
return line.substring(line.indexOf('_' + 1), line.lastIndexOf('_'));
in the method "extractNameOfRacer".
KMH_Kevin Magnussen_HAAS FERRARI, what is the name and what is the team?