Frage

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
War es hilfreich?

Lösung

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

Andere Tipps

I'm fairly certain the limit is technically is 2147483647, or Integer.MAX_VALUE. Perhaps the instructor was referring to a business rule for your particular program?

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top