Reputation: 151
I have a big String
to be converted into Stop
objects, but every time I use this function returns a java.lang.NumberFormatException: Invalid int: "1"
I don't understand why "1"
is not a valid String
to be converted in Int
...
Where am I wrong?
private static List<List<String>> rawToList(String string) {
List<List<String>> result = new ArrayList<>();
for (String row : Arrays.asList(string.split("\n")))
result.add(Arrays.asList(row.split(",")));
result.remove(0);
return result;
}
private static List<Stop> rawToStops(String string) {
List<Stop> stops = new ArrayList<>();
for (List<String> entity : rawToList(string))
stops.add(new Stop(
entity.get(0),
entity.get(1),
entity.get(2),
entity.get(3),
Double.parseDouble(entity.get(4)),
Double.parseDouble(entity.get(5)),
Integer.parseInt(entity.get(6)),
Integer.parseInt(entity.get(7))));
return stops;
}
The big String
is quite long. I read it from this txt file.
Upvotes: 0
Views: 519
Reputation: 151
Solved
I have to remove non-printable unicode characters with this:
string.replaceAll("\\p{C}", "");
Upvotes: 3