集册 Java实例教程 Java使用以下命令打印出列表中的元素

Java使用以下命令打印出列表中的元素

欢马劈雪     最近更新时间:2020-01-02 10:19:05

453
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
Java为每个

import java.util.*;/*时 代 J a v a 公 众 号*/


public class Ran {


    public static void main(String[] args) {

        

        // 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();

    }

}/** 来 自 N o w  J a v a  .   c o m**/


展开阅读全文