I think what pbrockway2 is getting at is that arrays are 0 bound.
Say you have the following array:
- String myArray[] = {"firstElement","secondElement","thirdElement"};
Since myArray has 3 elements, myArray.length will return 3.
The thing is that arrays in Java are 0 based. This means that the first element in the array resides at index 0.
So,
- myArray[0] will give you "firstElement",
- myArray[1] will give you "secondElement",
- and myArray[2] will give you "thridElement"
If you try to access myArray[3] you will get an error because the array index 3 doesn't exist.
Therefore if you have:
- String theLastElement = myArray[myArray.length];
You will get an exception. To retrieve the last element properly (without exception) you should be accessing the element at myArray.length-1 (which is the index of the last element):
- String theLastElement = myArray[myArray.length-1];
So, to fix your problem, change your code to:
- int var = Integer.parseInt(args[args.length-1]);
This will give you the last element in the "args" array.
(Please be aware that if the last element in the args array is not an Integer you will experience a different type of error....)
-Frinny