Skip to main content

Arrays in Java: (Part 2)

>

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;
    • Step 2: Initializing:
      • The syntax of initializing STATIC one dimensional array is:
        array_name = {value1, value2, value3 … valueN};
    • 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’ };
Click HERE for Examples of One Dimensional Arrays in Java

Comments

Relevant to YOU:

Popular posts from this blog

ASCII Code in Java (Part 1)

> The ASCII Code: (Part 1) ASCII stands for "American Standard Code for Information Interchange". As you may remember (Grade 9), computers only work with HIGH(1) and LOW(0) electrical states, known as bits, with correspond to mathematical Base 2 numbers. That is, computers only understand binary language. ASCII codes represent text (or other things) in computers. Assume that you are working with MS Word, or PPT or any other tool that uses text based inputs from user. You need to type a sentence that computer is not aware of. ASCII codes help to exchange this information between user and computer. When you type a character, it is converted into ASCII code first and then into Binary, which makes the computer understand what is to be typed. Hence every key on the keyboard has a specific ASCII code which is used to make the computer understand our language. If you press 4 from keyboard, then keyboard send the value 100 (value equival...

Arrays in Java (Part 4)

> Arrays in Java: (Part 4) One Dimensional Array : 1. Sum all elements of integer array 2. Find maximum and minimum element 3. Find the longest string (largest length string) Example: (Sum all elements of integer array) Example: (Find maximum and minimum element from integer array) Example: (Find longest string in a string array in java)

String Class in Java (Part 2)

> The String Class: (Part 2) Comparison Methods of String class: Example: (equals) Example: (equalsIgnoreCase) Example: (compareTo) Example: (compareToIgnoreCase) Example: (startsWith) Example: (endsWith) Example: (contains) Click HERE for the Simple Methods of String class. Click HERE for the Substring Methods of String class.