java-stream

    -1热度

    3回答

    流我是新来的Java流和Lambda表达式。我有这样的变量 - List<String> lines = Arrays.asList("ab,12,bd","df,23,df","ef,98,dg"); 我希望这些行为发生。 拆分列表中的每个元素。 提取结果数组中的第二个元素。 (这是数字)。 对其应用一些功能。为了简单起见,让我们将它乘以2. 然后收集结果作为列表,即包含24,46,196的

    3热度

    2回答

    我有一个List counties,它只包含唯一的县名,而List txcArray包含该城市的城市名称,县名和人口。 我需要从txcArray获得每个县的最大城市名称,只使用Java 8的lambda表达式和Stream s。 这里是我的代码至今: List<String> largest_city_name = counties.stream() .map(a -> t

    10热度

    3回答

    stream.spliterator()是否隐式关闭了stream,或者需要在之后明确关闭它? Stream<String> stream = Stream.of("a", "b", "c"); Spliterator<T> spliterator = stream.spliterator(); // Some low lever operation with the spliterator

    4热度

    2回答

    下面的代码获取流并对其进行排序。如果存在应该应用的最大限制,它将应用它。 if(maxLimit > 0) { return list.stream().sorted(comparator).limit(maxLimit).collect(Collectors.toList()); } else { return list.stream().sorted(comparator

    4热度

    1回答

    是否支持在Collectors.toMap内处理自定义异常。 我在调用MyException的Collector.toMap内调用一个方法。是否可以在调用函数pupulateValues()?中重新生成?为了演示,我使用下面的代码重新引发MyException,但无法通过。我的目标是在main方法中处理MyException。 public static void main(String[] ar

    3热度

    3回答

    我有一个类说Level(它只是一个理解的虚拟类)。 我想根据levelId排序TreeMap<Level,Set<String>>。 请从下面的代码 import java.util.*; import java.util.stream.Collectors; public class Level { int levelId; public Level(in

    0热度

    2回答

    这样: List<Integer> list = new LinkedList<>(); for (int i = 0; i < upperBound; i += step) { list.add(i); } 我怎么能取代它的功能与风格的流? 谢谢

    2热度

    2回答

    我希望得到列表,而不是数组列表的一个列表,下面的代码: List<String[]> list = org.simpleflatmapper.csv.CsvParser.reader(in).stream().collect(Collectors.toList()); 我们怎样才能得到List<List<String>> list = ...?

    -3热度

    1回答

    地图attributeMap =新TreeMap中<>(); attributeMap.put("C","FIRSTNAMe"); attributeMap.put("C2","LASTNAMe"); attributeMap.put("C3","1111"); attributeMap.put("C4","ABCNAMe"); 如何使上述示例的单字符串 输出为c

    5热度

    2回答

    请不要“if”语句,除非你解释为什么没有这个语句是不可能的。 我看到我可以走多远只能在流上操作。我有这样的滋扰: List<Cube> revised = cubes.filter(p) .map(c -> f(c)) .map(c -> { if(c.prop()) { c.addComment(comment); }