Search code examples
javascjp

args [] of main takes only ten elements?


In a video of the Oracle University for Java certification, the instructor just said that "the size of args is ten, so we can only send a maximum of ten elements". Has anybody heard of this?

I just tried it and it doesn't seem right.

package tests;

public class MainArgsSize {

    public static void main(String[] args) {
        for (String st : args) {
            System.out.println(st);
        }
    }
}
java tests.MainArgsSize 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

Solution

  • From the Java documentation:

    A Java application can accept any number of arguments from the command line.

    [source]

    However, these arguments are passed in the form of an array. From this link here: Do Java arrays have a maximum size?, the size of an array was discussed as being:

    Integer.MAX_VALUE - 5
    

    Therefore, that should be the limit.

    Edit: Thanks for @MrLore who provided the following link discussing the limits on Unix machines in his comment above:

    http://www.in-ulm.de/~mascheck/various/argmax/#results