>
Arrays in Java: (Part 2)
One Dimensional Array:
- - Array in the simplest form is one dimensional array (One-D). It has only rows for storing records. One D array of size 6 can be pictured as follows:
- Creating one dimensional arrays (STATIC):
- Step 1: Declaration:
- The syntax of declaring STATIC one dimensional arrays is:
datatype array_name[];
OR
datatype []array_name;
- The syntax of declaring STATIC one dimensional arrays is:
- Step 2: Initializing:
- The syntax of initializing STATIC one dimensional array is:
array_name = {value1, value2, value3 … valueN};
- The syntax of initializing STATIC one dimensional array is:
- As the values are given in “Initializing” step in STATIC array, there is no need of third step here. [Step1 and 2 can be combined as follows:]
- Declaring an Integer data type array :
int m[] = {21,85,48,54,78,96,321,54,47,87}; - Declaring a double (decimal values) data type array :
double m[] = {13.0, 322.15, 85.1, 63.12, 48.12, 78.0}; - Declaring a String data type array :
String m[] = {“Hello World”, “Hi!”, “abc@abc.com”}; - Declaring a Character data type array :
char m[] = {‘a’, ‘c’, ‘2′, ‘f’ };
- Declaring an Integer data type array :
- Step 1: Declaration:
Comments
Post a Comment