An Array in Disarray
This lesson recalls how we're already familiar with the arrays along with the chapter's briefing.
We'll cover the following
Chapter’s briefing
In this chapter, we will learn about the array. We have seen before that a variable is a location in memory that has a name that contains a value. This value could be any data type, such as int
. An array is also another kind of variable or a container object that holds a fixed number of values of a single type. Therefore, an array could be any data type, such as int
, or String
. We have used arrays before, in our last programs, unknowingly. Watch this code snippet below:
public static void main(String[] args){}
In every program, this is the entry point; the main
method has a parameter, which is an array of String
type.
Array in the main()
method
In many Java programs, you will see two types of main
methods:
public static void main(String[] args){}
public static void main(String args[]){}
In fact, in our previous examples, we have used the second type. From now on, we will be using the first one.
Why? Any particular reason?
No. Java allows both. Java makes no difference between these two statements. However, in this chapter, we will find that declaration of an array by using the second one is discouraged in their official documentation.
Logically, from now on, we will stick with the first one.
Get hands-on with 1400+ tech skills courses.