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