java-stream

    3熱度

    1回答

    我需要從stdin讀取整數列表,並將它們變成java.awt.Point(x,y)數組。 輸入的格式是X Y X Y X Y ... 我能做到這一點的非流路這樣, Scanner scanner = new Scanner(System.in).useDelimiter("\n"); String[] input = scanner.next().split("\\s+"); Point[]

    2熱度

    1回答

    我正在回答有關codefights問題,我發現這個問題 inputArray而不元件k - 1, 2k - 1, 3k - 1等 例 對於inputArray = [1,2,3, 4,5,6,7,8,9,10]和k = 3, 輸出應該是 extractEachKth = [1,2,4,5,7,8,10] 。 其中一個答案是下面的代碼,我不明白。 int i; int[] extractEach

    3熱度

    3回答

    我有一個List<String>,我要它,轉換成Map,通過分組長度相同String s轉換爲List使用String長度爲重點,分類順序。它可以使用 - Map<Integer, List<String>> result = new TreeMap<>(); for (String str : list) { if (!result.containsKey(str.length())

    0熱度

    1回答

    我想將字符串行轉換爲長數字。 我這樣做: String line = "eRNLpuGgnON"; char[] chars = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890-_".toCharArray(); Map<Character, Integer> charToInt = IntStrea

    7熱度

    3回答

    生成流元素的認識以便我讀該Java 8正式文檔: 流可以或可以不具有限定的遭遇順序。 某個流是否有遇到順序取決於源和中間操作。某些流源(例如List或 陣列)本質上是有序的,而其他(如HashSet) 則不是。 如果一個流被排序,在同一個源上重複執行相同的 流管道將產生相同的 結果;如果未訂購,重複執行可能會產生不同的結果。 試圖通過這個代碼 public class StreamOrderVal

    3熱度

    2回答

    List<Integer> list = Arrays.asList(3, 4, 6, 1, 2, 3, 5, 6); list.parallelStream().forEach(System.out::print); list.parallelStream().map(a -> a + 2).forEach(a -> System.out.println(Thread.currentTh

    3熱度

    2回答

    雙列表 的POJO是這樣的: public class Obj { List<Entities> entities; } public class Entities { List<Fields> fields; } public class Fields { List<Value> values; //Get only first member : v

    1熱度

    2回答

    我正在學習使用Java8和Stream進行操作。我有一個問題,我正在嘗試使用java8流解決。 我有Map<String, List<Integer>> accountMap型 數據的地圖 - {0000132861=[6613, 6170, 6206], 0000135932=[6613, 6170, 6206], 0000122989=[6613, 6170, 6206], 000013837

    5熱度

    2回答

    我想這個例子中遷移到Java 8: Map<String, String> data = new HashMap<String, String>() {{ put("name", "Middle"); put("prefix", "Front"); put("postfix", "Back"); }}; String title = ""; i

    7熱度

    1回答

    我是Java 8的新手。我正在學習流API的reduce方法。我看到一個奇怪的行爲與此代碼: public class PrdefinedCollectors { public static void main(String[] args) { Stream<Integer> stream = Stream.of(1, 2, 3, 4, 5, 6); List<I