Menu
Topics Index
...
`


Strings >
Siva Nookala - 07 Apr 2016
String Array is a container object that holds a fixed number of String values. The length of an String array is established when the array is created. After creation, its length is fixed.

Each item in an String array is called an element, and each element is accessed by its numerical index which starts with 0. Declaring a String arrays :
String names[] = new String[3]; // Declaring a String array with size
String names[] = {"Prem", "Siva", "Mahesh", "Srinath"}; // Declaring a String array with elements
String names[] = new String[]{"Prem", "Siva", "Mahesh", "Srinath"}; // Other way of declaring
String Arrays Demo
class StringArrayDemo
{
    public static void main(String[] args)
    {
        String names[] = {"Prem", "Siva", "Mahesh", "Srinath"};
        for(int i =0; i < names.length; i++)
        {
            System.out.println(names[i]);
        }
    }
}
OUTPUT

Prem
Siva
Mahesh
Srinath

DESCRIPTION

In the above program we declared a String array with elements and printed the elements in the array using a forward for loop.

THINGS TO TRY
  • Declare a String array with size of 4 and add elements to it.
  • Print the element in the names array in reverse order. Use reverse for loop.

0
Wrong
Score more than 2 points

© meritcampus 2016 - 2017

All Rights Reserved.