java-stream

    3热度

    1回答

    我想要一个接收DataFiles列表的方法,然后使用其谓之字段过滤其字段之一,并返回DataFiles列表而不是字符串。 这里是我的代码: public static List<DataFile> someMethod(List<DataFile> dataFiles) { return dataFiles .stream() .map(DataFile::g

    2热度

    2回答

    我有一个对象与多个字段。其中一个字段是List<Object2>。 我想恢复项目Object2的所有名称(Object2.getName())的List(或Set,因为我不需要重复)。 我试图做到这一点,如下所示: getList().stream() .map(Object::getListObject2) .collect(Collectors.toSet())

    0热度

    1回答

    ArrayList<Integer> digitList = new ArrayList<Integer>(); ArrayList<Integer> newBase = new ArrayList<Integer>(); public void toX(int base, int oNum) { while(base > 0) { digitList.add(base

    3热度

    2回答

    我有一个名为Test的类。这个类有一个名为getNumber的方法,它返回一个int值。 public class Test{ . . . . public int getNumber(){ return number; } } 另外我有一个HashMap,其中的关键是一个长和值是一个测试对象。 Map<Long, T

    3热度

    2回答

    是否有可能(以简单的方式)将其更改为java8Stream? (请不要评论/如果你想告诉我有两个for更好,不是所有的回路应改为流回答,它不是一个点) final Map<String, String> map = new HashMap<>(); for(final Person person: list) { for(final Internal internal: person

    -1热度

    3回答

    我有一个数组String[],我想转换为阵列Float[] 考虑e是经由HttpServletRequest::getParameterMap()供给的String[]。我想: Arrays.stream(e.getValue()).mapToDouble(Float::parseFloat).boxed().toArray(Float[]::new)); 了异常: java.lang.Arr

    10热度

    1回答

    如何才能流畅地创建流?在基于收集代码迁移我遇到了这种模式多次: Collection collection = veryExpensiveCollectionCreation(); return Stream.concat(firstStream, collection.stream()); 产生的级联流一般懒洋洋地处理,因为我们知道。因此,如果流处理在串联流的第一部分中停止,则根本不需要昂

    -1热度

    1回答

    假设我有一个像列表一样的列表; { {1-a12-abc,firstname,john}, {2-a12-abc,firstname,tom}, {1-a12-abc,lastname,doe}, {3-a22-abc,city,Delhi} } 我们可以把每个列表中包含一些PersonId,Attribute和attribute value。我想每个

    3热度

    3回答

    我想一个列表排序,然后组的元素。问题是,当我对元素进行分组时,排序顺序就是折腾。 下面是我的一段代码 listOfRooms.stream().sorted(Comparator.comparing(DXARoom::getStayAverageRate)) .collect(Collectors.groupingBy(DXARoom::getRoomInfoLabel)); 这是

    5热度

    1回答

    字符串格式我要排序的浮点值,其是在如字符串格式提供的名单列表, "rate": "429.0", "rate": "129.0", "rate": "1129.0",... 如果我使用Comparator.comparing (Room :: getRate),该列表将按字符串顺序排序,这将是不正确的。所以我写了下面的代码,我将String转换为float,然后进行比较。 下面的代码适合我