Tuesday, 27 October 2015

Java Tutorial : Java Array (Multidimensional Array - String)


Click here to watch in Youtube :
https://www.youtube.com/watch?v=4TfECaP8Gns&list=UUhwKlOVR041tngjerWxVccw

Click the below Image to Enlarge
Java Tutorial : Java Array (Multidimensional Array - String)
ArrayDemo.java
class ArrayDemo
{
    public static void main(String[] args)
    {

        String[][] strArray = new String[3][2];
        
        strArray[0][0] = "Ram";
        strArray[0][1] = "Peter";

        strArray[1][0] = "Apple";
        strArray[1][1] = "Ball";

        strArray[2][0] = "Bike";
        strArray[2][1] = "Car";
        
        System.out.println("Element at strArray[0][0] : " + strArray[0][0]);
        System.out.println("Element at strArray[0][1] : " + strArray[0][1]);

        System.out.println();

        System.out.println("Element at strArray[1][0] : " + strArray[1][0]);
        System.out.println("Element at strArray[1][1] : " + strArray[1][1]);

        System.out.println();

        System.out.println("Element at strArray[2][0] : " + strArray[2][0]);
        System.out.println("Element at strArray[2][1] : " + strArray[2][1]);

    }
}
Output
Element at strArray[0][0] : Ram
Element at strArray[0][1] : Peter

Element at strArray[1][0] : Apple
Element at strArray[1][1] : Ball

Element at strArray[2][0] : Bike
Element at strArray[2][1] : Car
ArrayLoopDemo.java
public class ArrayLoopDemo
{

    public static void main(String[] args)
    {
        String[][] strArray = new String[3][2];

        strArray[0][0] = "Ram";
        strArray[0][1] = "Peter";

        strArray[1][0] = "Apple";
        strArray[1][1] = "Ball";

        strArray[2][0] = "Bike";
        strArray[2][1] = "Car";

        int rows = strArray.length;

        System.out.println("Number of rows : " + rows + "\n");

        for (int i = 0; i < rows; i++)
        {
            int columns = strArray[i].length;

            System.out.println("Number of columns in row " + i + " is : "
                    + columns);

            for (int j = 0; j < columns; j++)
            {
                System.out.println("Element at " + "strArray[" + i + "]" + "["
                        + j + "] : " + strArray[i][j]);

            }
            System.out.println();
        }

    }

}
Output
Number of rows : 3

Number of columns in row 0 is : 2
Element at strArray[0][0] : Ram
Element at strArray[0][1] : Peter

Number of columns in row 1 is : 2
Element at strArray[1][0] : Apple
Element at strArray[1][1] : Ball

Number of columns in row 2 is : 2
Element at strArray[2][0] : Bike
Element at strArray[2][1] : Car
To Download ArrayDemoMultiDimensionalStringApp Project Click the below link
https://sites.google.com/site/javaee4321/java/ArrayDemoMultiDimensionalStringApp.zip?attredirects=0&d=1

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • No comments:

    Post a Comment

    Google+ Followers

    Google+ Badge