Skip to main content
added 23 characters in body
Source Link

as a matter of an excersice i would advise you to keep your parameters as List<String>...

public static void main(String[] args) {
    boolean printNewline = true;
    List<String> parameters = new ArrayList<>(Arrays.asList(args);
    if (args.length > 0 && isNewLine(args[0]) ) {
        printNewline = false;
        parameters.remove(0); //remove the first one
    }

    String output = parameters.stream()
        .collect(Collectors.joining(" ", "", printNewLine ? "\n"System.lineSeparator() : ",")"")

    System.out.printlnprint(output);
}
    

NOTE: the method isNewLine() is not shown here - but you should consider using such a method to prevent a missing argument... think of -n, -N, /n, /N, all these parameters can be handle in the isNewLine-method...

as a matter of an excersice i would advise you to keep your parameters as List<String>...

public static void main(String[] args) {
    boolean printNewline = true;
    List<String> parameters = new ArrayList<>(Arrays.asList(args);
    if (args.length > 0 && isNewLine(args[0]) ) {
        printNewline = false;
        parameters.remove(0); //remove the first one
    }

    String output = parameters.stream()
        .collect(Collectors.joining(printNewLine ? "\n" : ","))

    System.out.println(output);
}
    

NOTE: the method isNewLine() is not shown here - but you should consider using such a method to prevent a missing argument... think of -n, -N, /n, /N, all these parameters can be handle in the isNewLine-method...

as a matter of an excersice i would advise you to keep your parameters as List<String>...

public static void main(String[] args) {
    boolean printNewline = true;
    List<String> parameters = new ArrayList<>(Arrays.asList(args);
    if (args.length > 0 && isNewLine(args[0]) ) {
        printNewline = false;
        parameters.remove(0); //remove the first one
    }

    String output = parameters.stream()
        .collect(Collectors.joining(" ", "", printNewLine ? System.lineSeparator() : "")

    System.out.print(output);
}
    

NOTE: the method isNewLine() is not shown here - but you should consider using such a method to prevent a missing argument... think of -n, -N, /n, /N, all these parameters can be handle in the isNewLine-method...

deleted 1 character in body
Source Link

as a matter of an excersice i would advise you to keep your parameters as List<String>...

public static void main(String[] args) {
    boolean printNewline = true;
    List<String> parameters = new ArrayList<>(Arrays.asList(args);
    if (args.length > 0 && isNewLine(args[0]) ) {
        printNewline = false;
        parameters.remove(0); //remove the first one
    }

    String output = parameters.stream()
        .collect(Collectors.joining(printNewLine ? "\n" : ","))

    System.out.println(output);
}
    

NOTE: the method isNewLine() is not shown here - but you should consider using such a method to prevent a missing argument... think of -n, -N, /n, /N, all these parameters can be handleshandle in the isNewLine-method...

as a matter of an excersice i would advise you to keep your parameters as List<String>...

public static void main(String[] args) {
    boolean printNewline = true;
    List<String> parameters = new ArrayList<>(Arrays.asList(args);
    if (args.length > 0 && isNewLine(args[0]) ) {
        printNewline = false;
        parameters.remove(0); //remove the first one
    }

    String output = parameters.stream()
        .collect(Collectors.joining(printNewLine ? "\n" : ","))

    System.out.println(output);
}
    

NOTE: the method isNewLine() is not shown here - but you should consider using such a method to prevent a missing argument... think of -n, -N, /n, /N, all these parameters can be handles in the isNewLine-method...

as a matter of an excersice i would advise you to keep your parameters as List<String>...

public static void main(String[] args) {
    boolean printNewline = true;
    List<String> parameters = new ArrayList<>(Arrays.asList(args);
    if (args.length > 0 && isNewLine(args[0]) ) {
        printNewline = false;
        parameters.remove(0); //remove the first one
    }

    String output = parameters.stream()
        .collect(Collectors.joining(printNewLine ? "\n" : ","))

    System.out.println(output);
}
    

NOTE: the method isNewLine() is not shown here - but you should consider using such a method to prevent a missing argument... think of -n, -N, /n, /N, all these parameters can be handle in the isNewLine-method...

deleted 62 characters in body
Source Link
Landei
  • 7.1k
  • 2
  • 25
  • 34

as a matter of an excersice i would advise you to keep your parameters as List<String>...

public static void main(String[] args) {
    boolean printNewline = true;
    List<String> parameters = new ArrayList<>(Arrays.asList(args);
    if (args.length > 0 && isNewLine(args[0]) ) {
        printNewline = false;
        parameters.remove(0); //remove the first one
    }

    String output = printNewLine?
         parameters.stream().collect(Collectors.joining("\n")):
         parameters.stream().collect(Collectors.joining(printNewLine ? "\n" : ","));

    System.out.println(output);
}
    

NOTE: the method isNewLine() is not shown here - but you should consider using such a method to prevent a missing argument... think of -n, -N, /n, /N, all these parameters can be handles in the isNewLine-method...

as a matter of an excersice i would advise you to keep your parameters as List<String>...

public static void main(String[] args) {
    boolean printNewline = true;
    List<String> parameters = new ArrayList<>(Arrays.asList(args);
    if (args.length > 0 && isNewLine(args[0]) ) {
        printNewline = false;
        parameters.remove(0); //remove the first one
    }

    String output = printNewLine?
         parameters.stream().collect(Collectors.joining("\n")):
         parameters.stream().collect(Collectors.joining(","));

    System.out.println(output);
}
    

NOTE: the method isNewLine() is not shown here - but you should consider using such a method to prevent a missing argument... think of -n, -N, /n, /N, all these parameters can be handles in the isNewLine-method...

as a matter of an excersice i would advise you to keep your parameters as List<String>...

public static void main(String[] args) {
    boolean printNewline = true;
    List<String> parameters = new ArrayList<>(Arrays.asList(args);
    if (args.length > 0 && isNewLine(args[0]) ) {
        printNewline = false;
        parameters.remove(0); //remove the first one
    }

    String output = parameters.stream()
        .collect(Collectors.joining(printNewLine ? "\n" : ","))

    System.out.println(output);
}
    

NOTE: the method isNewLine() is not shown here - but you should consider using such a method to prevent a missing argument... think of -n, -N, /n, /N, all these parameters can be handles in the isNewLine-method...

Source Link
Loading