1. For loop
// 1 for (int i = 0; i < list.size (); i++) { int item = list.get (i); System.out.println ("This is the first" + (i+1) + "A: Value:" + Item); } // 2 int j = 0; for (int i:list) { + +J; System.out.println ("This is the first" + j + ": Value:" + i); }
Recommended notation 2
2. HashMap traversal
map<string,string> map=New hashmap<string,string>(); Map.put ("1", "value1"); Map.put ("2", "value2"); Map.put ("3", "Value3"); Map.put ("4", "Value4");
// the third type: recommended, especially when the capacity is large System.out.println ("\ n traverse key and value through Map.entryset") ; for (map.entry<string, string> entry:map.entrySet ()) { System.out.println ("Key:" + entry.getkey () + "Value:" +Entry.getvalue ()); }
3. How to output the stack information of Printstacktrace () when using log4j
Log.error (E.getmessage (), E)
4. String concatenation
StringBuilder tmpstr== tmpstr.tostring ();
Recommended Java notation