Home > Back-end > Lambda expressions foreach how to acquire the traverse index
Lambda expressions foreach how to acquire the traverse index
Time:11-23
Public static void main (String args []) { List List=Java. Util. Arrays. AsList (" a ", "b", "c"); List. The forEach (s - & gt; { //how to obtain traversal to which one now, such as the index System. The out. Println (s); }); }
CodePudding user response:
His first cap
CodePudding user response:
for (int i=0; I & lt; List. The size (); I++) { System.out.println(i); }
CodePudding user response:
Want to use lambda expressions
CodePudding user response:
Public static void main (String args []) { List List=Java. Util. Arrays. AsList (" a ", "b", "c"); Int id=0; List. The forEach (s - & gt; { //how to obtain traversal to which one now, such as the index Id=list. IndexOf (s); System. The out. Println (id); System. The out. Println (s); }); }