Key Concepts

Review core concepts you need to learn to master this subject


int[] marks = {50, 55, 60, 70, 80}; System.out.println(marks[0]); // Output: 50 System.out.println(marks[4]); // Output: 80

An index refers to an element’s position within an array.

The index of an array starts from 0 and goes up to one less than the total length of the array.

Learn Java: Arrays
Lesson 1 of 2
  1. 1
    We have seen how to store single pieces of data in variables. What happens when we need to store a group of data? What if we have a list of students in a classroom? Or a ranking of the top 10 horse…
  2. 2
    Imagine that we’re using a program to keep track of the prices of different clothing items we want to buy. We would want a list of the prices and a list of the items they correspond to. To create a…
  3. 3
    When we printed out the array we created in the last exercise, we saw a memory address that did not help us understand what was contained in the array. If we want to have a more descriptive printo…
  4. 4
    Now that we have an array declared and initialized, we want to be able to get values out of it. We use square brackets, [ and ], to access data at a certain index: double[] prices = {13.1, 15.87,…
  5. 5
    We can also create empty arrays and then fill the items one by one. Empty arrays have to be initialized with a fixed size: String[] menuItems = new String[5]; Once you declare this size, it cann…
  6. 6
    What if we have an array storing all the usernames for our program, and we want to quickly see how many users we have? To get the length of an array, we can access the length field of the array obj…
  7. 7
    When we write main() methods for our programs, we use the parameter String[] args. Now that we know about array syntax, we can start to parse what this means. A String[] is an array made up of St…
  8. 8
    We have now seen how to store a list of values in arrays. We can use this knowledge to make organized programs with more complex variables. Throughout the lesson, we have learned about: - Creatin…

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo