小编use*_*674的帖子

获取匹配条件的第一个元素

如何获得与流中的条件匹配的第一个元素?我试过这个但是没用

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)

java java-8 java-stream

98
推荐指数
3
解决办法
10万
查看次数

GetBytes()返回负数

*"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值?

java string

7
推荐指数
1
解决办法
4726
查看次数

标签 统计

java ×2

java-8 ×1

java-stream ×1

string ×1