Monday, 30 April 2018

Java: Printing ALL Args as single string

You can simply String.join the strings together and print them. Like:



public class Foo {

public static void main(String [] args) {

System.out.println(String.join(" ",args));
}

}


The first argument, the delimiter, is here " " (a string containing one space). Such that there is a space between two arguments.



Note that this program is almost identical to the echo program you see on a lot of operating systems.



Finally note that although this program does not contain a loop, the String.join definitely need some form of looping inside the method.

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...