如何获得与流中的条件匹配的第一个元素?我试过这个但是没用
this.stops.stream().filter(Stop s-> s.getStation().getName().equals(name));
Run Code Online (Sandbox Code Playgroud)
该条件不起作用,filter方法在Stop之外的其他类中调用.
public class Train {
private final String name;
private final SortedSet<Stop> stops;
public Train(String name) {
this.name = name;
this.stops = new TreeSet<Stop>();
}
public void addStop(Stop stop) {
this.stops.add(stop);
}
public Stop getFirstStation() {
return this.getStops().first();
}
public Stop getLastStation() {
return this.getStops().last();
}
public SortedSet<Stop> getStops() {
return stops;
}
public SortedSet<Stop> getStopsAfter(String name) {
// return this.stops.subSet(, toElement);
return null;
}
}
import java.util.ArrayList;
import java.util.List;
public class Station {
private final …Run Code Online (Sandbox Code Playgroud) *"Hätten Hüte ein ä im Namen, wären sie möglicherweise keine Hüte mehr, sondern Häte."
72 -61 -92 116 116 101 ...*
Run Code Online (Sandbox Code Playgroud)
GetBytes()在char'ä'返回负数(-61,()).
如何获得正常的ascii值?