Skip to main content

Java For Python Programmers Edition 2

Section 3.5 Arrays

As was said at the outset of this section, we are going to use Java ArrayLists because they are easier to use and more closely match the way that Python lists behave. However, if you look at Java code on the internet or even in your core Java books you are going to see examples of something called an array. In fact, you have already seen one example of an array declared in the ‘Hello World’ program. Let’s rewrite this program to use primitive arrays rather than array lists.
The main difference between this example and the previous example is that we declare count to be an Array of integers. We also can initialize short arrays directly using the syntax shown on line 8. Then notice that on line 22 we can use the square bracket notation to index into an array.
You have attempted of activities on this page.