这里的short-circuiting是指:有时候需要在遍历中途停止操作,比如查找第一个满足条件的元素或者limit操作。在Stream中short-circuiting操作有:anyMatch、allMatch、noneMatch、findFirst、findAny、limit,这些操作在Sink中都有一个变量来判断是否短路,比如limit用的是m,match用的是stop,find用的是hasValue。
The behavior of this operation is explicitly nondeterministic(不确定的); it is free to select any element in the stream. This is to allow for maximal performance in parallel operations; the cost is that multiple invocations(调用) on the same source may not return the same result. (If a stable result is desired, use
findFirst()
instead.)
可以看到findAny()操作,返回的元素是不确定的,对于同一个列表多次调用findAny()有可能会返回不同的值。使用findAny()是为了更高效的性能。如果是数据较少,串行地情况下,一般会返回第一个结果,如果是并行的情况,那就不能确保是第一个。比如下面的例子会随机地返回OptionalInt[50]。
试验了一下java stream中的findAny和findFirst,发现都返回了列表中的第一个元素。那么,这两种方法的区别是什么呢?查看了一下Java API document:findFirst:findFirstOptional<T>findFirst()Returns anOptionaldescribing the first element ...
前言:
java
8在使用流时候会用到findAny() 与findFirst() 方法使用,下面就对这两个方法使用结合源码做下区分。
首先我们来看下源码:
这两个方法都是在接口Stream类
中
:
1 .findFirst() 方法根据命名可以大致知道是获取Optional流
中
的第一个元素
2 .findAny() 方法是获取Optional 流
中
任意一个,存在随机性,其实里面也是获取元素
中
的第一个
具体实现方法是类似的,看下源码ReferencePipeline
@Override
Java
8 的Stream语法可以说是声明式bai的代码了,所du以正如名字所说,是找到任何一个就行zhi
比如:有一个Integer的集dao合[1, 3, 5, 7]
e.g 1
List<Integer> list = Arrays.asList(1, 3, 5, 7);
Optional<Integer> any = list.stream().findAny();
这样出来的话,这个any肯定就是1了,因为此时stream是有顺序的,相当于一个list,把list
中
的数字按
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/huanghanqian/article/details/102807972
专栏收录该内容
18 篇文章0 订阅
试验了一下
java
stream
中
的findAny和findFirst,发现都返回了列表
中
的第一个元素。那么,这两种方法的
区别
是什么呢?
查看了一下
Java
API document:
findFirst
程序如下:
/*********************************************************************************************************
* 获取文件夹内所有文件名并打印到txt
中
************************************************************
My first encounter with the
Java
programming language was during a one-week
Java
training session in 1997. I did
not get a chance to use
Java
in a project until 1999. I read two
Java
books and took a
Java
2 Programmer certification
examination. I did very well on the test, scoring 95 percent. The th
启点CE过NP
中
文December 24 2018:Cheat Engine 6.8.2 Released:
Here's a new version for the hollidays. Mainly minor improvements and some small bugfixes, but also a new 'ultimap like' feature called Code Filter for which you don't need any special hardware for. (Just an extensive list of addresses) Download: Cheat Engine 6.8.2
Fixes:
Disassembler: Several disassembler instructions had a comma too many or too few ,fixed those
Disassembler: Fixed the description for ret #
Disassembler/Debug: Fixed the address that is being edited when a breakpoint hits while editing an instruction
Assembler: Fixed assembling reg*2/4/8+unquotedsymbol
Plugin: Fixed the SDK for C plugins that use the disassembler callback
Hotkeys: Fixed the attach to foreground hotkey
Memory Scan: Fixed the percentage scan
Memory Scan: Fixed a rare situation that could cause an error
Memory Scan: Simple values now works with groupscan
Memory Scan Lua: Scanfiles now also get deleted if the memory scan object is freed before the scan is fully done
Fill Memory: Now allows 64-bit addresses
Structure Dissect: Fixed the popupmenu "change type" so it now affects all selected entries instead of just the first
PointerOrPointee window: Fix the debug pointer or pointee window button text when using access instead of writes
GUI: Fixed and restored the DPI Aware option in setting
GUI: Some DPI fixes/adjustments here and there
Graphical Memory view: Fixed DPI issues
Symbolhandler: When the symbolhandler now waits till it's done, it won't wait for the structures to be parsed anymore
Additions and Changes:
Lua Engine: Added autocomplete
DLL injection: On DLL injection failure CE tries to fall back on forced injection methods
Assembler: Added multibyte NOP
Plugins: Plugins can now have side dll's that are statically linked in their own folder (Windows 7 with updates and later)
Debugging: Improved the FPU window editing when single stepping, allowing you to change the FPU registers
Debugging: Threadview now updates when single stepping and cnanges made there will affect the currently debugged thread (before it didn't)
Debugging: Added Code Filter. This lets you filter out code based on if it has been executed or not (Uses software breakpoints)
Debugging: Added an option to chose if you wish to break on unexpected breakpoints, and if CE should break on unexpected breakpoints, or only on specified regions (like AA scripts)
Disassembler: The comments now show multiple parameters
Pointerscan: Add option to allow negative offset scanning
Pointerscan: Add extra types to the display
Advanced Options/CodeList: Now uses symbolnames
Tutorial Game: Added a levelskip option when you've solved a step
Tutorial Game: Added a secondary test
Compare memory: Added a limit to the number of address values shown per row (can be changed)
Address List: When the option to deactivate children is set, the children will get deactivated first
Memory Scan: Add a lua script in autorun that lets you specify which module to scan
ExecuteCodeEx(Let's you execute code in the target and pass parameters)
Added 2 new parameters to getNameFromAddress (ModuleNames and Symbols)
Added addModule and deleteModule to the symbollist class
Added the ModuleLoader class which can force load dll's
Fixed endUpdate for the listview
Thanks go out to SER[G]ANT for updating the russion translation files already
June 23 2018:Cheat Engine 6.8.1 Released:
Apparently 6.8 contained a couple of annoying bugs, so here's an update that should hopefully resolve most issues.
Also a few new features that can come handy
Download: Cheat Engine 6.8.1
Fixes:
Fixed several issues with the structure compare
Fixed the commonality scanner from picking up unrelated registers for comparison
Fixed speedhack hotkeys
Fixed ultimap 1
Fixed a bunch of random access violations
Fixed Lua dissectCode.getStringReferences now also returns the string
Fixed Lua breakpoints that specify a specific function
Fixed Lua toAddress when the 2nd parameter is an address
Fixed assembling xmm,m32
Fixed issue when disassembling AVX instructions
Fixed rightclicking r8-r9 in the registers window
Fixed the plugin system for DBVM
Fixed DBVM memory allocations when smaller than 4KB
Additions and changes:
Added translation strings for the all type settings
You can now drop files into the auto assembler
auto assembler commands allocnx (allocate no execute) and allocxo (allocate execute only)
The memoryview windows's hexadecimalview now shows the allocationbase as well, and can be doubleclicked to go there
Added support for mono dll's that do not export g_free
Changed "make page writable" to multiple options
Improved DBVM speed slightly
added RemoteThread class object
June 8 2018:Cheat Engine 6.8 Released:
Cheat Engine 6.8 has been released. Lots of new features like structure compare, AVX disassembling support, lua functions, etc...
Download:
If you encounter bugs or have suggestions, please do not hesitate to report them in the forum, bugtracker or by e-mail.
And if you have questions, don't hesitate to ask them in the forum
Fixes:
Fixed some more high dpi issues
Fixed issues with the dropdown list in memory records
Fixed pointer offset symbols not calculating properly
Fixed registered binutils
Fixed graphical issues with the tablist
Fixed issue where memory blocks would get cut of before the page end
Fixed some memory leaks
Fixed some graphical issues in the addresslist
Fixed rightclick on r8 and r9 in memoryview
Fixed disassembling some instructions
Fixed DBVM so it works on windows 1709 and later (tested on 1803)
Fixed several DBVM offload crashes
Fixed freeze with allow increase/decrease for 8 byte long values
Fixed several issues where minimizing a window and then close it would hang CE
Fixed file scanning
Fixed crashes when editing memory in some some emulators
Additions and changes:
Text editor improvements
Added hundreds of new cpu instructions
Mono now has some new features like instancing of objects
Mono instances window is now a treeview where you can see the fields and values
"find what addresses this code accesses" can also be used on RET instructions now (useful to find callers)
The graphical memory view now has a lot more options to set it just the way you need
Codepage support in hexview
structure data from PDB files can now be used, and are stored in a database for lookup later
dissect structures form can now show a list of known structures (pdb, mono, ...)
Added a "revert to saved scan" option (lets you undo changes)
Added a "forgot scan" option (in case you forgot what you're doing)
Pointerscan limit nodes is default on in a new ce install (remembers your choice when you disable it)
Autoattach now happens using a thread instead of a gui blocking timer
Some colorscheme enhancements
Added a DBVM based "Find what writes/accesses" feature. (For pro users, enable kernelmode options for it to show)
Changed the dissect data setup from seperate yes/no/value dialogs to a single window
Added a bypass option for ultimap2 on windows 1709. When using ranges, do not use interrupts, or use DBVM
Added find what writes/access to the foundlist
Autoassembler scriptblocks are now grouped when written to memory
Added {$try}/{$except} to auto assembler scripts
Added an extra tutorial/practice target
Added cut/copy/paste context menu items to pointer offset fields in add/change address, and added a context menu to the pointer destination
Added an automated structure compare for two groups of addresses to find ways to distinguish between them
added automatic garbage collection and settings to configure it
added new functions:
gc_setPassive
gc_setActive
reinitializeSelfSymbolhandler
registerStructureAndElementListCallback
showSelectionList
changed the getWindowlist output
MainForm.OnProcessOpened (better use this instead of onOpenProcess)
enumStructureForms
cpuid
getHotkeyHandlerThread
bunch of dbvm_ functions (needs dbvm capable cpu, and intel only atm)
and more, including class methods and fields (read celua.txt)
Minor patches:
06/08/2018: 6.8.0.4 - Fixed speedhack hotkey speed asignments and some commonalityscanner issues 06/09/2018: 6.8.0.5 - Fixed only when down speedhack option 06/10/2018: 6.8.0.6 - Fixed ultimap1 - Fixed ultimap2 on some systems - Fixed enableDRM() from crashing - Fixed one disassembler instruction
Russian translation has been updated
November 13 2017:Can't run Cheat Engine
There is apparently some malware going around that blocks execution of Cheat Engine (Saying file missing, check filename, etc...) If you have been a victim of this then try this windows repair tool to fix your windows install:
Download Repair Tool
November 9 2017:Spanish(Latin) translation added
Manuel Ibacache M. from Chile has provided us with spanish(Latin) translation files for Cheat Engine.
They can be downloaded from the download section where you can find the other translation files, or right here
June 7 2017:Cheat Engine 6.7 Released:
Cheat Engine 6.7 has been released. New lua functions, GUI improvements, codepage scanning, several bugfixes and more(See below).
Download: Cheat Engine 6.7
If you encounter bugs or have suggestions, please do not hesitate to report them in the forum, bugtracker, irc or by e-mail.
And if you have questions, don't hesitate to ask them in the forum , irc
Fixes:
Fixed some DPI issues at some spots
Fixed the "Not" scan for ALL
"simple values" now also applies to the All type
Fixed not adding the 0-terminator to strings when the option was set to add it
Fixed ultimap hotkeys
Fixed ultimap2 filtering
Changing pointers in the change address dialog won't set/override global memrec and address anymore (local now)
Fixed show as signed not working for custom types
Fixed several issues with the structure spider
Fixed 64-bit registers in the tracer getting truncated on doubleclick, and fix r8 to r15
Fixed copy/paste in the scanvalue
Fixed kernelmode QueryMemoryRegions for windows build 1607
Fixed some disassembler errors
Fixed lua command fullAccess
Fixed text to speech if launched from a different thread
Fixed clicking on checkboxes when the dpi is different
Fixed the found code dialog count size
Fixed mono freezing Cheat Engine when it crashes/freezes
Additions and changes:
Changed the processlist and added an Applications view similar to the taskmanager
Small change to the tutorial first step wording
Structure Dissect: Added RLE compression (by mgr.inz.player) and other things to improve filesize
Structure Dissect: If setting a name, it will also be shown in the header
The symbolhandler can now deal with complex pointer notations
Added support for single-ToPA systems for ultimap2
Added some more spots where the history will be remebered in memoryview
Memoryrecords with auto assembler scripts can now execute their code asynchronous (rightclick and set "Execute asynchronous")
Kernelmode memory reading/writing is safer now
Added an option to filter out readable paths in the pointerscan rescan
Added "codePage" support
Added font/display options to several places in CE
Added a search/replace to the script editors
You can now delete addresses and reset the count from "Find what addresses this code accesses"
Added a statusbar to the hexview in memoryview
Pointerscan for value scans now add the results to the overflow queue
Opening a file and changing bytes do not change them to the file anymore (you need to explicitly save now)
Added an option to the processlist to filter out system processes
Added a system to let users sign their tables so you know you can trust their tables.
Memory record dropdown lists can now reference those of others. USe as entry text: (memoryrecorddescription)
Added an option to notify users of new versions of Cheat Engine
Custom Types can now be referenced from Lua
Auto assembler lua sections now have access to "memrec" which is the memory record they get executed from. Can be nil
stringToMD5String now support strings with a 0 byte in them
autoAssemble() now also returns a disableInfo object as 2nd parameter. You can use this to disable a script
added Action and Value properties to MemoryRecordHotkey objects
added screenToClient and clientToScreen for Control objects
added readSmallInteger and writeSmallInteger
added enableDRM()
added openFileAsProcess/saveOpenedFile
added saveCurrentStateAsDesign for CEForm objects
added disableWithoutExecute and disableAllWithoutExecute
added OnCustomDraw* events to the listview
added being/endUpdate for the Strings class
added SQL support
added color overrides to the disassembler text
added OnPaint to the CustomControl class
added autoAssembleCheck to syntax check an AA script
fixed the addresslist returning nil for PopupMenu (while popupMenu did work)
added an timeout option for pipes
added some graphical options
added some low level system functions
Russian translation has been updated
Chinese translation has been updated
May 15 2017:Korean language files
Thanks to Petrus Kim there are now Korean language files for Cheat Engine. You can get them here
Just extract it to the language folder in the Cheat Engine installation folder and you'll be able to use it
April 13 2017:Cheat Engine for Macintosh download
For the Mac users under us there is now a mac version available for download. It's based on Cheat engine 6.2 but I will be upgrading it to 6.6 and later based on the feedback I get.
Tip:if you have trouble opening processes: Reboot your Mac and hold CMD+R during boot to enter the recovery console. There open the terminal (using the top menu) and enter "csrutil disable" . Then reboot and you'll be able to open most processes (Youtube video by NewAgeSoldier in case it's not clear)
October 6 2016:Cheat Engine 6.6 Released:
Cheat Engine 6.6 has been released. It has several fixes, new scan functionality, gui changes/improvements, Ultimap 2, better hotkeys, more programming options, and more(See below).
Download: Cheat Engine 6.6
If you encounter bugs or have suggestions, please do not hesitate to report them in the forum, bugtracker, irc or by e-mail.
And if you have questions, don't hesitate to ask them in the forum or irc
Fixes:
Fixed saving of hotkey sounds
Fixed the CF flag in the disassembler stepping mode
Fixed Kernelmode VirtualQueryEx for Windows 10 build 14393
Fixed DBVM for Windows 10 build 14393
Fixed the shortest assembler instruction picking for some instructions
Fixed a few bugs in the break and trace routine when you'd stop it while the thread still had a single step set
Fixed several ansi to UTF8 incompatbilities that poped up between 6.5 and 6.5.1
Fixed the stackview not properly setting the color, and giving an error when trying to change a color
Fixed the exe generator not adding both .sys files or the .sig files when using kernel functions
Fixed some places of the disassembler where it helps guessing if something is a float or not
When using the code finder, it won't show the previous instruction anymore if it's on a REP MOVS* instruction
Fixed an issue when editing memoryrecords with strings, where wordwrap would add newline characters
Fixed D3D alpha channel for textures and fontmaps
Fixed the helpfile not being searchable
The installer will now mark the CE destination folder as accessible by APPS. (fixes speedhack for some APPS)
Fixed the form designed crashing is resized 'wrong'
Additions and changes:
Ultimap 2 for Intel CPU's of generation 6 and later (no DBVM needed for those)
Language select if you have multiple language files for CE
Memoryrecord pointer offsets can use calculations, symbols and lua code now
While stepping in the debugger you can now easily change the EIP/RIP register by pressing ctrl+f4
changed the way CE is brought to front when a hotkey is pressed
Made the GUI more adaptive to different fontsizes and DPI
Several font and minor GUI changes
Added DPIAware and a font override to the settings window. (DPI aware is on by default, but can be turned of if experiencing issues)
Added option to enable pause by default
Disassembling mega jumps/calls now show the code in one line
The standalone auto assembler window will now give an option to go to the first allocated memory address
Changed the point where the settings are loaded in CE's startup sequence
The formdesigner now allows copy and paste of multiple objects, and uses text
Added scrollbox and radiogroup to the formdesigner
Added Middle, MB4 and MB5 as allowable hotkeys
Added controller keys as hotkeys
Single stepping now shows an indication if an condition jump will be taken
Added a watchlist to the debugger
Added the 'align' assembler pseudo command (allocates memory so the next line is aligned on a block of the required size)
Added the 'Not' option for scans, which causes all addresses that match the given entry as invalid
Changed the Unicode text to UTF-16. Text scans are now UTF8/UTF16 (no codepage)
Hexview can now show and edit values in 3 different textencodings. (Ascii, UTF-8 and UTF-16)
Rescan pointerscans on pointerscans that where done on a range can now change the offset
speak(): Text to speech
hookWndProc: a function that lets you hook the windows message handler of a window
registerEXETrainerFeature: Lets you add extra files to the exe trainer file packer
getFileVersion(): A function to get version information from a file
mouse_event() : Lets you send mouse events to windows. (move, click, etc...)
loadFontFromStream() : Lets you load a font from a memory stream. (Useful for trainers that use a custom font)
added several thread synchronization objects
control class: added bringToFront and sendToBack
lua changes:
dbk_writesIgnoreWriteProtection() now also disables virtualprotectex calls from CE
loadTable() can now also load from a Stream object.
the addresslist has some Color properties published for better customization
the LUA server has had some new commands added so hooked code can do more efficient calls. (LUAClient dll has been updated to use them in a basic way)
Russian translation has been updated
French tutorial only translation has been updated as well
10/10/2016:6.6.0.1: Fixed align
May 19 2016:Cheat Engine 6.5.1 Released:
6.5.1 has been released. It's mainly a bugfix version to replace 6.5 which had a few minor bugs that needed solving.
Download: Cheat Engine 6.5.1
Fixes:
Fixed increased value by/decreased value by for float values
Fixed disassembling/assembling some instructions (64-bit)
Fixed the autoassembler tokenizing wrong words
Fixed several bugs related to the structure dissect window (mainly shown when autodestroy was on)
Fixed a small saving issue
Groupscans now deal with alignment issues better
Fixed
java
support for 32-bit
Additions and changes:
Signed with a sha256 signature as well (for OS'es that support it)
Changed Ultimap to use an official way to get the perfmon interrupt instead of IDT hooking (less BSOD on win10 and 8)
Individual hotkeys can now play sounds
Now compiled with fpc 3.0/lazarus 1.6 (Previously 2.7/1.1)
You can now search in the string list
PEInfo now has a copy to clipboard
Some places can now deal better with mistakes
Lazarus .LFM files can now be loaded and saved
Fixed several incompatibilities between lua that popped up in 6.5 (due to the lua 5.1 to 5.3 change)
Fixed the OnSelectionChange callback property in the memoryview object
MemoryRecords now have an Collapsed property
Added TCanResizeEvent to the splitter
Fixed setBreakpoint not setting a proper trigger if not provided
Fixed executeCode* parameter passing
Fixed several memory leaks where unregistering hooks/addons didn't free the internal call object
Some tableFile additions
Fixed registerAssemble assembler commands
Added kernelmode alloc and (un)mapping functionality
Added an easy way to add auto assembler templates
Added window related functions including sendMessage
Added Xbox360 controller support functions
Added more thread functions
Post release fixes:
Dealt with several gui issues like the mainform to front on modal dialogs, header resizing stuck with the cursor, treeview item selection/deletion being weird, etc...
Added a disconnect to the client in pointerscans
Fixed pointerscan issue with 32-bit aligned pointers in a 64-bit process
Fixed a deadlock in threads when lua custom types where used
Post release fixes:
Dealt with several gui issues like the mainform to front on modal dialogs, header resizing stuck with the cursor, treeview item selection/deletion being weird, etc...
Added a disconnect to the client in pointerscans
fixed pointerscan issue with 32-bit aligned pointers in a 64-bit process
Fixed a deadlock in threads when lua custom types where used
Fixed pointerscan resume
6/1/2016: (major bugfix) properly fixed resume of pointerscans and alignment fix
December 31 2015:Cheat Engine 6.5 Released:
I'd like to announce the release of Cheat Engine 6.5
If you encounter bugs or have suggestions, please do not hesitate to report them in the forum, bugtracker, irc or by e-mail.
And if you have questions, don't hesitate to ask them in the forum or irc
Fixes:
Fixed page exception breakpoints from not working
Fixed the save as button in the lua script assigned to the table
Fixed the dotnetdatacollector from not fetching parent fields
Fixed disassembling of some instructions
Fixed assembling some instructions
Fixed assembling instructions that referenced address 80000000 to ffffffff in 64-bit targets
Fixed dealing with unexpected breakpoints
Fixed several issues with the network scanner. (symbols, scanspeed, threads, etc...)
Fixed "going to" 64-bit registers.
Fixed pointerstrings for 64-bit
Fixed the addressparser in memview's hexview not handing static 64-bit addresses
Fixed r8 and r9 looking broken in the memoryview window
Fixed hotkeys that set a value as hexadecimal and the value is smaller than 0x10
Fixed multiline string editing for memory records
Fixed dragging cheat tables into CE
Fixed VEH debug for 'Modern' apps
Fixed several translation issues
fixed getStructureCount, writeRegionToFile, readRegionFromFile, readInteger, ListColum.GetCount
fixed memoryleak in MemoryStream
Several fixes to DBVM:
added support for Windows 10
support for more than 8 cpu's
support for newer cpu's
fixed issue where calling CPUID right after setting the TF flag wouldn't trigger a breakpoint after it
Additions and changes:
Array of Byte's can now deal with nibble's. (e.g: 9* *0 90 is now a valid input- and scanstring)
The auto assembler can now deal with some mistakes like forgetting to declare a label
Added support to use binutils as assembler and disassembler, and a special scripting language for it
Added support for 64-bit mono, and script support for cases where mono.dll isn't called mono.dll
Added an option to get a list of all recently accessed memory regions. This is useful for the pointerscanner
The pointerscanner can now use multiple snapshots (pointermaps) to do a scan. This basically lets you do a rescan during the first scan, saving your harddisk
Made the pointerscan network scanner a bit easier to use. You can now join and leave a pointerscan session
You can now stop pointerscans and resume them at a later time
Pointerscan files can get converted to and from sqlite database files
The pointerscan configuration window now has an advanced and basic mode display
The all type now has a setting that lets you define what under "all" falls
Custom types now also have access to the address they're being used on
Split up the "(de)activating this (de)activates children" into two seperate options (one for activate, one for deactivate)
Added some basic Thumb disassembling
The xmplayer has been replaced with mikmod which supports many different module types (in lua you still call it xmplayer)
Rightlicking on "your system supports dbvm" will let you manually load DBVM for each cpu. This is usefull if for some reason your system crashes when it's done too quickly
In "Find what addresses this instruction accesses" you can now open the structure dissect window of your choice in case there are others. It will also fill in the base address, so no need to recalculate yourself
AA command GlobalAlloc now has an optional 3th parameter that lets you specify the prefered region
Added an option to record and undo writes. (Off by default, can be enabled in settings. Memview ctrl+z will undo the last edit)
Added aobscanregion(name,startaddress,stopaddress,aob)
switched from Lua 5.1 to 5.3
debug_setBreakpoint can now take an OnBreakpoint parameter that lets you set a specific function just for that breakpoint
added dbk_getPhysicalAddress(int)
added dbk_writesIgnoreWriteProtection(bool)
added getWindowList()
And a bunch of other lua functions. (check out main.lua)
Post release fixes (max 7 days after initial release *or 30 if a HUGE bug):
1/6/2016:Fixed structure dissect from crashing when autodestroy is on
1/6/2016:Fixed window position loading on multi monitor systems
1/6/2016:Fixed the lua customtype and
1/6/2016:Several minor gui fixe
My first encounter with the
Java
programming language was during a one-week
Java
training session in 1997. I did
not get a chance to use
Java
in a project until 1999. I read two
Java
books and took a
Java
2 Programmer certification
examination. I did very well on the test, scoring 95 percent. The three questions that I missed on the test made me
realize that the books I read did not adequately cover all of the details on all of the necessary
Java
topics. I made up
my mind to write a book on the
Java
programming language. So, I formulated a plan to cover most of the topics that
a
Java
developer needs understand to use the
Java
programming language effectively in a project, as well as to get a
certification. I initially planned to cover all essential topics in
Java
in 700 to 800 pages.
As I progressed, I realized that a book covering most of the
Java
topics in detail could not be written in 700 to 800
hundred pages. One chapter that covered data types, operators, and statements spanned 90 pages. I was then faced
with the question, “Should I shorten the content of the book or include all the details that I think a
Java
developer
needs?” I opted for including all the details in the book, rather than shortening the content to keep the number of
pages low. It has never been my intent to make lots of money from this book. I was never in a hurry to finish this book
because that rush could have compromised the quality and the coverage of its contents. In short, I wrote this book
to help the
Java
community understand and use the
Java
programming language effectively, without having to read
many books on the same subject. I wrote this book with the plan that it would be a comprehensive one-stop reference
for everyone who wants to learn and grasp the intricacies of the
Java
programming language.
One of my high school teachers used to tell us that if one wanted to understand a building, one must first
understand the bricks, steel, and mortar that make up the building. The same l
在
Java
8 Stream
中
,findFirst()返回Stream
中
的第一个元素,而findAny()返回Stream
中
的任何元素。
1. findFirst()
1.1 从整数流
中
找到第一个元素。
DemoFindFirst1.
java
public class DemoFindFirst1 {
public static void main(String[] args) {
List<Integer> list = Arrays.asList(1, 2, 3, 2
对于
中
间操作和终端操作的定义,请看《
JAVA
8 stream接口
中
间操作和终端操作》,这篇主要讲述的是stream的min,max,findFirst,findAny操作,我们先看下函数的定义
Optional<T> min(Comparator<? super T> comparator);
Optional<T> max(Compa...
先上代码:
public static void main(String[] args) {
List<String> list1 = Arrays.asList("A1", "B1", "C1", "A2", "B2", "C2", "A3", "B3", "C3");
List<String> list2 = Arrays.asList("A1", "B1", "C1", "A2", "B2", "C2", "A3", "B3", "C3");
stream findAny和findFirst是
Java
8
中
Stream API提供的两个方法,用于在流
中
查找元素。
findAny方法返回流
中
的任意一个元素,如果流为空则返回一个空的Optional对象。
findFirst方法返回流
中
的第一个元素,如果流为空则返回一个空的Optional对象。
这两个方法都可以用于并行流,但是findAny方法在并行流
中
的效率更高,因为它不需要保证返回流
中
的第一个元素。