Search code examples
javaarraysprimitiveprimitive-typesindexoutofboundsexception

Java - What is the simplest was to find if a position exists in an array of primitives?


I have an array of characters, and, for the type of program I have, it will have to check indexes over the boundaries by design. I thought I'd got around this but evidently not. So is there a way to check if an index is out of bounds or not?


Solution

  • Get the array.length which gives how many elements exists in array. Available index will be one less than length of array.