forked from freeCodeCamp/freeCodeCamp
-
Notifications
You must be signed in to change notification settings - Fork 2
Java Array
Quincy Larson edited this page Aug 20, 2016
·
1 revision
An Array is used to store a collection of data of similar datatype. Arrays always start with the index of 0.
Syntax:
dataType[] name_of_array; // preferred way.
or
dataType name_of_array[]; // works but not preferred way
double[] list; //preferred way.
or
double list[]; //works but not preferred way.
Note: The style double list[]
is not preferred as it comes from the C/C++ language and was adopted in Java to accommodate C/C++ programmers.
dataType[] name_of_array = new dataType[arraySize];
double[] List = new double[10];
dataType[] name_of_array = {value0, value1, ..., valuek};
double[] list = {1, 2, 3, 4};
Example of code:
int[] a = new int[] {4,5,6,7,8}; //declare array
for (int i=0; i<a.length; i++) //loop goes through each index
{
System.out.println(a[i]); //prints the array
}
🚀 Run Code
Output:
4
5
6
7
8
Source: Java Arrays
Learn to code and help nonprofits. Join our open source community in 15 seconds at http://freecodecamp.com
Follow our Medium blog
Follow Quincy on Quora
Follow us on Twitter
Like us on Facebook
And be sure to click the "Star" button in the upper right of this page.
New to Free Code Camp?
JS Concepts
JS Language Reference
- arguments
- Array.prototype.filter
- Array.prototype.indexOf
- Array.prototype.map
- Array.prototype.pop
- Array.prototype.push
- Array.prototype.shift
- Array.prototype.slice
- Array.prototype.some
- Array.prototype.toString
- Boolean
- for loop
- for..in loop
- for..of loop
- String.prototype.split
- String.prototype.toLowerCase
- String.prototype.toUpperCase
- undefined
Other Links