我假设我的问题从标题中已经很清楚了。
我有两个类:parent A and child B.和want to have return like Map<Integer,A> key is a field from child B。我已经从数据库中提取了List<A> aList。类定义:
public class B {
Integer id;
String some;
String some2;
}
public class A {
Integer id;
B someB;
String name;
}
我试着像aLi
我需要使用流创建两个方法。返回每个任务的平均分数的方法。
public Map<String, Double> averageScoresPerTask(Stream<CourseResult> results) {}
以及返回平均得分最高的任务的方法。
public String easiestTask(Stream<CourseResult> results) {}
我只能修改这两种方法。
这是CourseResult类
public class CourseResult {
private final Person person
我有一个List<String>,我必须将它转换为Map,方法是将相同长度的String分组到List中,使用String长度作为关键字,按排序顺序排列。可以使用以下命令来完成-
Map<Integer, List<String>> result = new TreeMap<>();
for (String str : list) {
if (!result.containsKey(str.length())) {
result.put(str.length(), new ArrayList<>());
我知道Flow是,ShaerdFlow是。
为了测试Kotlin流中的冷流,我创建了下面的代码。我的计划是创建一个将发出字符串值并在其上添加两个收集器的流。我希望只有一个收集器会得到发出的值,因为它是一个冷流。
但是结果是不同的,我发现有两个值被发出了!
测试代码:
val stringFlow: Flow<String> = flow<String> {
for (i in 0..10) {
Timber.d("Integer $i emitted ${currentCoroutineContext()}"
我很难找到如何使用流作为数组从对象列表中获取不同的整数。
假设我有下一节课:
public class Person{
private int age;
private double height;
public Person(int age, double height) {
this.age= age;
this.height = height;
}
public int getAge() {
return age;
}
public double getHeight() {