We change the number of words in our game by returning a smaller number in the
getSize()
method. Instead of
WORD_LIST.length
, we simply return 5. We now see
only the first 5 words in our array, looping back to the first word once we
reach the end.
If we make getSize()
return 50, then we get a problem once we get past the end
of the array. Fortunately Java behaves safely and just causes an
ArrayIndexOutOfBoundsException
. In other languages this can cause bad issues
as we can then access memory that we should not see. I will talk more about
this in the next section.
We hope you enjoyed this tutorial. If you did, you will also enjoy our courses. We suggest you start with Extreme Java - Advanced Java, followed by Extreme Java - Concurrency Performance for Java 8.
We deliver relevant courses, by top Java developers to produce more resourceful and efficient programmers within their organisations.
We can help make your Java application run faster and trouble-shoot concurrency and performance bugs...