?????????????????????????δ???????????????????????????????У???????????????????????CPU?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????:
?????????????
????????????????????????С????????????????????????????????????????????limit()??distinct()?????????????£???ж?OK???
????IntStream.iterate(0?? i -> ( i + 1 ) % 2)
????.limit(10)
????.distinct()
????.forEach(System.out::println);
????????????????
????0
????1
??????????????????????????????????С?????10????????(0 1 0 1 0 1 0 1 0 1)??????????????????????й????????????????????????0??1????
???????????????????????????????????????????????????????10?????????????????????10????????????????????????????
???????????????SQL????????????????????????????????SQL Server 2012??????????????????SQL???????????
????-- Using TOP
????SELECT DISTINCT TOP 10 *
????FROM i
????ORDER BY ..
????-- Using FETCH
????SELECT *
????FROM i
????ORDER BY ..
????OFFSET 0 ROWS
????FETCH NEXT 10 ROWS ONLY
??????????????SQL??????????????????????????????????
??????????????
????????????SQL????????????MySQL????PostgreSQL?????????????LIMIT .. OFFSET???SQL?????????????????????????????SQL Server 2012?е????????????????OFFSET????????????С?
?????????MySQL/PostgreSQL?????????????????????????????????
????IntStream.iterate(0?? i -> i + 1)
????.limit(10) // LIMIT
????.skip(5)   // OFFSET
????.forEach(System.out::println);
??????????????????
????5
????6
????7
????8
????9
?????????????9?????????????????Ч????limit()???????????(0 1 2 3 4 5 6 7 8 9)????β???skip()?????????????(5 6 7 8 9)????????????????????
????????LIMIT .. OFFSET??OFFSET .. LIMIT?????壡
??????ù????????????????
?????????????????????????????ù????????????????????????????
????Files.walk(Paths.get("."))
????.filter(p -> !p.toFile().getName().startsWith("."))
????.forEach(System.out::println);
???????????????????????????????е????????????????????????Щ?????????????????????????????????walk()????????????????????μ?????????????????????????????????????????????е???·????????????????????????????????????????????????Щ??????????????в??????.git????.idea??????·?????????:..git efs????..idealibraries?????????????????????
?????????????????????д??
????Files.walk(Paths.get("."))
????.filter(p -> !p.toString().contains(File.separator + "."))
????.forEach(System.out::println);
??????????д????????????????????????????????????????????е???????????????
?????????????????????JDK1.0????????File.list()??????????????? FilenameFilter??FileFilter?????????????????
?????????????????
???????????б???????????????????????????????б???????Java 8?????????????????Java 8??????????????????????????0??9???б??
????// Of course?? we create this list using streams:
????List<Integer> list =
????IntStream.range(0?? 10)
????.boxed()
????.collect(toCollection(ArrayList::new));
??????????????????????????????????????????
????list.stream()
????// remove(Object)?? not remove(int)!
????.peek(list::remove)
????.forEach(System.out::println);
???????????????е??Щ????п????????????????????????????????
????0
????2
????4
????6
????8
????null
????null
????null
????null
????null
????java.util.ConcurrentModificationException
???????????????????????????б???????????????????顣??????????
????[1?? 3?? 5?? 7?? 9]
???????е????????????????????BUG?????????????????????????????JDK???????????ArrayList.ArraListSpliterator????????????????

 

????/* * If ArrayLists were immutable?? or structurally immutable (no * adds?? removes?? etc)?? we could implement their spliterators * with Arrays.spliterator. Instead we detect as much * interference during traversal as practical without * sacrificing much performance. We rely primarily on * modCounts. These are not guaranteed to detect concurrency * violations?? and are sometimes overly conservative about * within-thread interference?? but detect enough problems to * be worthwhile in practice. To carry this out?? we (1) lazily * initialize fence and expectedModCount until the latest * point that we need to commit to the state we are checking * against; thus improving precision. (This doesn't apply to * SubLists?? that create spliterators with current non-lazy * values). (2) We perform only a single * ConcurrentModificationException check at the end of forEach * (the most performance-sensitive method). When using forEach * (as opposed to iterators)?? we can normally only detect * interference after actions?? not before. Further * CME-triggering checks apply to all other possible * violations of assumptions for example null or too-small * elementData array given its size()?? that could only have * occurred due to interference. This allows the inner loop * of forEach to run without any further checks?? and * simplifies lambda-resolution. While this does entail a * number of checks?? note that in the common case of * list.stream().forEach(a)?? no checks or other computation * occur anywhere other than inside forEach itself. The other * less-often-used methods cannot take advantage of most of * these streamlinings. */

??????????????????????????????????????????
????list.stream()
????.sorted()
????.peek(list::remove)
????.forEach(System.out::println);
?????????????????????????????

 

????0
????1
????2
????3
????4
????5
????6
????7
????8
????9

?????????????????б??????
????[]
???????????е??????????????????????sorted()?????????“???????м????”??????ζ??????????????????????????????????????????????????????в????????????????????б????????????