In actual development, the collections and arrays are more than we use, and collections/arrays encapsulates a lot of features for us to call, and can meet most of our development needs, so understand what they are all very necessary!
Collections:
Sort function
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/5E/wKioL1XiU9nQw94oAABfBlxRhtk546.jpg "title=" Sogou _ 2015-08-30_08-43-36.png "alt=" Wkiol1xiu9nqw94oaabfblxrhtk546.jpg "/>
Specifically for list sorting, in actual development, we do often need to sort a list with some objects in it!
Min and Max
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/62/wKiom1XiUm3zU86CAACqBCF1SC0341.jpg "title=" Sogou _ 2015-08-30_08-46-40.png "alt=" Wkiom1xium3zu86caacqbcf1sc0341.jpg "/>
If we want to take a minimum and maximum value from a set, how do we get it quickly? The above method will help us to achieve.
Reverse
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/62/wKiom1XiU7uBm0qtAAAe_F_9gEU814.jpg "title=" Sogou _ 2015-08-30_08-52-31.png "alt=" Wkiom1xiu7ubm0qtaaae_f_9geu814.jpg "/>
If, we just need to get a list of the reverse order!
Mixed arrangement
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/62/wKiom1XiVsuCetCoAAAbtHoA7jM320.jpg "title=" Sogou _ 2015-08-30_09-05-33.png "alt=" Wkiom1xivsucetcoaaabthoa7jm320.jpg "/>
By this method, the order of the elements in the list is unpredictable, that is, the order is random and mixed.
What's the use of it?
For example, in some businesses, we want to provide the external data is "change", assuming that the e-commerce app, the user sees is always the same goods, and what are the interests of buying? The use of random features, so that users can see the same every time!
Copy
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/62/wKiom1XiWO_zMkcTAAA1TnibLUw385.jpg "title=" Sogou _ 2015-08-30_09-14-41.png "alt=" Wkiom1xiwo_zmkctaaa1tnibluw385.jpg "/>
Duplicate operations often, it should be noted that the length of the dest list needs to >=src list length, copy from Index=0, and is a shallow copy!
Find the index position of the first/last where the target list appears
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/5F/wKioL1XiX_miK-FHAAA7e7d0IHQ838.jpg "title=" Sogou _ 2015-08-30_09-35-44.png "alt=" Wkiol1xix_mik-fhaaa7e7d0ihq838.jpg "/>
We can take a look at how the source code is implemented:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/62/wKiom1XiXxTz3lMtAAM5zd0ZPR8371.jpg "title=" Sogou _ 2015-08-30_09-40-54.png "alt=" Wkiom1xixxtz3lmtaam5zd0zpr8371.jpg "/>
Description
If we do this function ourselves, how will we do it?
For finding the target List2 in the source List1, it is clear that the first step is to traverse List1, starting from index=0 to find out if each element corresponds to List2, and if not, repeat the process from index=1.
The above code, divided into ordinary for version and iterator version, the idea is consistent.
It is important to note that the continue in the inner for loop is not intended to start the next inner for loop, but rather to cause the outer for loop to start the next time, in order to achieve this, the continue lable is used;
Circular moving Rotate
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/62/wKiom1XiYwKzFhFFAAA9rSzFQXo492.jpg "title=" Sogou _ 2015-08-30_09-57-40.png "alt=" Wkiom1xiywkzfhffaaa9rszfqxo492.jpg "/>
If we want to move the first few in the list to the end, or the last few moves to the front, rotate can come in handy!
How did he make it? Seems like there's no clue? See how the source code is done:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/63/wKiom1XiambxxWrhAADB3iMXAHU358.jpg "title=" Sogou _ 2015-08-30_10-29-13.png "alt=" Wkiom1xiambxxwrhaadb3imxahu358.jpg "/> The schematic is as follows: 650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/63/wKiom1XiayfBbevFAACPvpCuG-0267.jpg "title=" Sogou _ 2015-08-30_10-32-22.png "alt=" Wkiom1xiayfbbevfaacpvpcug-0267.jpg "/>
Just a few reverse to achieve, so simple!
Sentiment:
This means that some seemingly complex functions are assembled by a small number of features!
|