java 101, how do I count the number of arguments passed into main?

user1464251 picture user1464251 · Jul 25, 2012 · Viewed 41.2k times · Source

For example

public static void main(String[] args) {
            int count = 0;
        for (String s: args) {
            System.out.println(s);
                count++;

        }

    }

is there some way of doing something like

int count = args.length()? or args.size()?

Answer

jrad picture jrad · Jul 25, 2012

It would be:

int count = args.length;