HTML Templates — php?

前端 未结 4 1513
时光说笑
时光说笑 2021-02-05 23:20

So, I\'m making a site about WWI as a school assignment, and I want this to appear in every document:





    <         


        
4条回答
  •  耶瑟儿~
    2020-11-21 02:35

    Arrays.toString

    As a direct answer, the solution provided by several, including @Esko, using the Arrays.toString and Arrays.deepToString methods, is simply the best.

    Java 8 - Stream.collect(joining()), Stream.forEach

    Below I try to list some of the other methods suggested, attempting to improve a little, with the most notable addition being the use of the Stream.collect operator, using a joining Collector, to mimic what the String.join is doing.

    int[] ints = new int[] {1, 2, 3, 4, 5};
    System.out.println(IntStream.of(ints).mapToObj(Integer::toString).collect(Collectors.joining(", ")));
    System.out.println(IntStream.of(ints).boxed().map(Object::toString).collect(Collectors.joining(", ")));
    System.out.println(Arrays.toString(ints));
    
    String[] strs = new String[] {"John", "Mary", "Bob"};
    System.out.println(Stream.of(strs).collect(Collectors.joining(", ")));
    System.out.println(String.join(", ", strs));
    System.out.println(Arrays.toString(strs));
    
    DayOfWeek [] days = { FRIDAY, MONDAY, TUESDAY };
    System.out.println(Stream.of(days).map(Object::toString).collect(Collectors.joining(", ")));
    System.out.println(Arrays.toString(days));
    
    // These options are not the same as each item is printed on a new line:
    IntStream.of(ints).forEach(System.out::println);
    Stream.of(strs).forEach(System.out::println);
    Stream.of(days).forEach(System.out::println);
    

提交回复
热议问题