import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class InListUsingForeach {
public static void main(String[] args) {
// TODO Auto-generated method stub
// Get and shuffle the list of arguments
List<String> argList = Arrays.asList(args);
Collections.shuffle(argList);
// Print out the elements using JDK 8 Streams
argList.stream()
.forEach(e->System.out.format("%s ",e));
// Print out the elements using for-each
for (String arg: argList) {
System.out.format("%s ", arg);
}
System.out.println();
}
}
使用了Lambda表達(dá)式...