Java traversal map, List, Array

Source: Internet
Author: User

1. Iterate through the array, using a For loop or foreach (I recommend it)

int arr[] = {2, 3, 1};  System.out.println ("----1----one-dimensional array before sorting");    for (int  x:arr) {  // Output The value  of the array element individually }

2. Traversing HashMap, it is recommended to use an iterator or a foreach

 Public DoubleGetpaymoney () {//using the foreach traversal         for(Goodorder goodorder:goodorderslist) {ListGoodorder.getgood (); //using for Traversal             for(inti = 0; I < goods.size (); i++) {map map=Goods.get (i); Iterator ITER=Map.entryset (). iterator (); //using iterators to traverse                 while(Iter.hasnext ()) {Map.entry Entry=(Map.entry) iter.next (); intCount =(Integer) Entry.getkey (); Good GD=(good) entry.getvalue (); Paymoney= (double.valueof (Paymoney) + double.valueof (Gd.getgood_price ()) *count); }            }        }        returnPaymoney; }

3. Traverse ArrayList

It is recommended to use a For loop to resolve (internal not locked, the most efficient, but when writing multi-threading to consider the problem of concurrent operations; the other two are when the state of the lock is accessed)

Java traversal map, List, Array

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.