Monday, April 30, 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

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...