当前位置:网站首页>Enhanced for loop
Enhanced for loop
2022-07-04 02:36:00 【XGTX1998】
1、 Introduce
enhance for The role of circulation : Simplify the writing format of iterators .( Be careful : enhance for The bottom layer of the loop still uses iterator traversal .)
enhance for Scope of application of the cycle : If it is realized Iterable Interface objects or array objects can be enhanced for loop .
enhance for Disadvantages of circulation : enhance for Circulation and iterator The effect of traversal is the same , That is to say, enhance for The inside of the loop is the call iteratoer Realized , But enhance for Circulation has some disadvantages , For example, you can't dynamically delete the contents of a collection in an enhancement loop 、 Can't get subscripts, etc .
2、 enhance for The format of the loop
for( data type Variable name : Traversal target )
{
data type
Variable name : Declare a variable to receive the element after traversal of the traversal target
}
3、 enhance for Circulation considerations
1、 enhance for The bottom layer of the loop is also obtained by using iterators , Just get the iterator by jvm complete , We don't need to get iterators , So we're using enhancements for In the process of looping variable elements, it is not allowed to use set objects to modify the number of elements in the set .
2、 Iterators traverse elements and enhance for The difference between cyclic variable elements : When iterators are used to traverse the elements of a collection, the elements of the collection can be deleted , And enhance for When looping elements of a variable set , Cannot call iterator's remove Method deletion except Elements .
3、 Ordinary for Circulation and enhancement for Difference between cycles : Ordinary for A loop can have no traversal target , And enhance for Loops must have traversal targets .
边栏推荐
- Life cycle of instance variables, static variables and local variables
- I stepped on a foundation pit today
- Write the first CUDA program
- Hunan University | robust Multi-Agent Reinforcement Learning in noisy environment
- Keepalived set the master not to recapture the VIP after fault recovery (it is invalid to solve nopreempt)
- The boss said: whoever wants to use double to define the amount of goods, just pack up and go
- 17. File i/o buffer
- C # learning notes: structure of CS documents
- Pytoch residual network RESNET
- Final consistency of MESI cache in CPU -- why does CPU need cache
猜你喜欢
Crawler practice website image batch download
High level application of SQL statements in MySQL database (I)
What is the student party's Bluetooth headset recommendation? Student party easy to use Bluetooth headset recommended
Talking about custom conditions and handling errors in MySQL Foundation
A fan summed up so many interview questions for you. There is always one you need!
Yyds dry goods inventory hand-in-hand teach you the development of Tiktok series video batch Downloader
7 * 24-hour business without interruption! Practice of applying multiple live landing in rookie villages
Unity knapsack system (code to center and exchange items)
The boss said: whoever wants to use double to define the amount of goods, just pack up and go
Valentine's Day - 9 jigsaw puzzles with deep love in wechat circle of friends
随机推荐
Dans la recherche de l'intelligence humaine ai, Meta a misé sur l'apprentissage auto - supervisé
Optimization theory: definition of convex function + generalized convex function
Life cycle of instance variables, static variables and local variables
String: LV1 eat hot pot
Question C: Huffman tree
[software implementation series] software implementation interview questions with SQL joint query diagram
96% of the collected traffic is prevented by bubble mart of cloud hosting
12. Gettimeofday() and time()
Global and Chinese market of handheld melanoma scanners 2022-2028: Research Report on technology, participants, trends, market size and share
ZABBIX API batch delete a template of the host
LV1 tire pressure monitoring
Winter vacation daily question -- a single element in an ordered array
Global and Chinese market for travel wheelchairs 2022-2028: Research Report on technology, participants, trends, market size and share
Small program graduation project based on wechat e-book small program graduation project opening report function reference
A. Min Max Swap
Yyds dry goods inventory it's not easy to say I love you | use the minimum web API to upload files
Example 073 square sum value judgment programming requires the input of a and B, if a ²+ b ² If the result of is greater than 100, a is output ²+ b ² Value, otherwise output the result of a + B.
LV1 Roche limit
A. ABC
Crawler practice website image batch download