rozchodzi się o to zadanie
https://www.codewars.com/kata/salesmans-travel/train/java
stworzylem takiego potworka :
public static class Adress {
public String zipCode;
public String houseNr;
public String street;
public Adress(String adress) {
String[] values = adress.split(" ");
String x = "";
this.zipCode = values[values.length - 2] + " "+ values[values.length - 1];
this.houseNr = values[0];
for (int i = 1; i < values.length - 2; i++) {
x += values[i] + " ";
}
this.street = x.substring(0, x.length() - 1);
}
}
public static String travel(String r, String zipcode) {
String[] singleAdress = r.split(",");
List<Adress> list = Arrays.stream(singleAdress)
.map(Adress::new)
.filter(adress -> adress.zipCode.equals(zipcode))
.collect(Collectors.toList());
String street = "";
String numer = "";
for (Adress x : list) {
street += x.street + ",";
numer += x.houseNr + ",";
}
numer = numer.substring(0, numer.length() - 1);
street = street.substring(0, street.length() - 1);
return zipcode + ":" + street + "/" + numer;
}
i teraz chcialbym uniknac tej petli for do budowania stringow. Czy da sie zbudowac ten return string juz w streamie?