From 05e14f0fb6b657ab47c6943b44d62752220479ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9D=92=E9=9F=B5?= <1320162752@qq.com> Date: Sat, 17 Sep 2022 11:14:05 +0800 Subject: [PATCH] =?UTF-8?q?StreamUtil.of(Iterable)=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/cn/hutool/core/stream/StreamUtil.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/hutool-core/src/main/java/cn/hutool/core/stream/StreamUtil.java b/hutool-core/src/main/java/cn/hutool/core/stream/StreamUtil.java index 89a304b9b..6b654dd73 100644 --- a/hutool-core/src/main/java/cn/hutool/core/stream/StreamUtil.java +++ b/hutool-core/src/main/java/cn/hutool/core/stream/StreamUtil.java @@ -1,6 +1,5 @@ package cn.hutool.core.stream; -import cn.hutool.core.collection.CollUtil; import cn.hutool.core.io.IORuntimeException; import cn.hutool.core.lang.Assert; import cn.hutool.core.util.CharsetUtil; @@ -10,6 +9,7 @@ import java.io.IOException; import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; +import java.util.Collection; import java.util.Iterator; import java.util.Spliterators; import java.util.function.Function; @@ -52,9 +52,10 @@ public class StreamUtil { */ public static Stream of(Iterable iterable, boolean parallel) { Assert.notNull(iterable, "Iterable must be not null!"); - return StreamSupport.stream( - Spliterators.spliterator(CollUtil.toCollection(iterable), 0), - parallel); + + return iterable instanceof Collection ? + ((Collection) iterable).stream() : + StreamSupport.stream(iterable.spliterator(), parallel); } /**