+ Reply to Thread
Results 1 to 9 of 9

Thread: Java:Tutorial - Arrays

  1. #1
    Co-Administrator John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John's Avatar
    Join Date
    Jul 2006
    Age
    21
    Posts
    5,885
    Blog Entries
    25

    Java:Tutorial - Arrays

    In an earlier tutorial, we looked at how to store a single value to a variable, similarly an array is a named place to store a SET of values allowing you to group common types.

    Sometimes, it becomes necessary to order variables in a list to spot trends:

    Temperature on Sept 1 = 90
    Temperature on Sept 2 = 87
    Temperature on Sept 3 = 84
    This is the ideal application for an array. All the variables and values are of the same type, integers, string, or what ever. Moreover there order and place in the list is important. Since an array allows you to store a “list” of values as a single “variable,” there must be a means of referencing each item. This reference is called an index. So therefore:

    If
    Code:
    Temp[1] = 90
    Temp[2] = 87
    Temp[3] = 84
    Then
    Code:
    int x = 2;
    Temp[ x ] = 87;
    At first, a concept that is difficult to grasp is that the index starts at 0. There for, an array with 5 elements contains the index values {0, 1, 2, 3, 4} but how do we make an array?


    Code:
    int z[ ] = new int[5];
    A working example might look like this:
    Code:
    int x;
    int z[] = new int[10];
    for (x = 0; x < 10; x++) {
    z[x] = x;
    }
    Therefore z[4] = 4! Arrays do not have to be numbers, for example:

    Code:
     int x;
    String myArray[ ] = new String[5];
    myArray[0] = "hello";
    myArray[1] = "this";
    myArray[2] = "is";
    myArray[3] = "an";
    myArray[4] = "array";
    for (x=0; x <= 4; x=x+1  )
    {
    System.out.println( myArray[x] );
    }
    You can accomplish the same thing in less lines of code by using the following:
    Code:
    int x;
    String myArray[] = {"hello", "this", "is", "an", "array"};
    for (x=0; x<=4; x++){
    System.out.println( myArray[x] );
    }
    If a single list of values isnt powerfull enough, we also have the ablilty to use miltidimensional arrays. This is sometimes refrered to as a matrix. Each index has its own set of indicies that are pared with it, for example:

    Code:
    int matrix[][] = {{1,2,3,4}, {4,5,6,7}, {7,8,9,10}};
    for (int i=0; i<=2; i++){
    for (int j=0; j<=3; j++){
    System.out.println( matrix[i][j] );
    }
    }

  2. #2
    Code Warrior Turk4n has much to be proud of Turk4n has much to be proud of Turk4n has much to be proud of Turk4n has much to be proud of Turk4n has much to be proud of Turk4n has much to be proud of Turk4n has much to be proud of Turk4n has much to be proud of Turk4n's Avatar
    Join Date
    May 2008
    Location
    4chan.org/g/
    Age
    20
    Posts
    3,836
    Blog Entries
    4

    Smile Re: Java:Tutorial - Arrays

    I just had to reply to this wonderful thread!

    I mean Wow, normally people just make random explanations with no real sense; But you made one with quite awsome style, thank you for this great thread.

  3. #3
    Learning Programmer Maze is an unknown quantity at this point Maze's Avatar
    Join Date
    Dec 2008
    Posts
    32

    Re: Java:Tutorial - Arrays

    Thanks for nice share. It was really good.

    I need some more examples about multi dimensional arrays. Could you explain and put some more examples about?

    THanks

  4. #4
    Administrator Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan's Avatar
    Join Date
    Nov 2005
    Location
    Hendersonville, NC
    Posts
    24,556
    Blog Entries
    97

    Re: Java:Tutorial - Arrays

    I've never seen this tutorial or at least I cannot ever remember reading it. Very nice, thank you. +rep

  5. #5
    Newbie miromtm is an unknown quantity at this point miromtm's Avatar
    Join Date
    Nov 2008
    Location
    CAIRO
    Age
    18
    Posts
    18

    Re: Java:Tutorial - Arrays

    WOW , man am very thankful ,

  6. #6
    Code Warrior Turk4n has much to be proud of Turk4n has much to be proud of Turk4n has much to be proud of Turk4n has much to be proud of Turk4n has much to be proud of Turk4n has much to be proud of Turk4n has much to be proud of Turk4n has much to be proud of Turk4n's Avatar
    Join Date
    May 2008
    Location
    4chan.org/g/
    Age
    20
    Posts
    3,836
    Blog Entries
    4

    Re: Java:Tutorial - Arrays

    Quote Originally Posted by miromtm View Post
    WOW , man am very thankful ,
    Good to see happy faces

    Hatsune Miku ~❤❤❤
    初音ミク。~❤❤❤

  7. #7
    Programming Expert whitey6993 has a spectacular aura about whitey6993 has a spectacular aura about whitey6993's Avatar
    Join Date
    Dec 2008
    Location
    In front of my Computer
    Posts
    408

    Re: Java:Tutorial - Arrays

    Excellent tutorial for introducing arrays and multi-dimensional arrays.

  8. #8
    Newbie Aroos is an unknown quantity at this point
    Join Date
    Jun 2009
    Posts
    1

    Post java:Tutorial

    Thanks for nice share. It was really good.

    I need some more examples about multi dimensional arrays java . Could you explain and put some more examples about?

    THanks

  9. #9
    Code Warrior Turk4n has much to be proud of Turk4n has much to be proud of Turk4n has much to be proud of Turk4n has much to be proud of Turk4n has much to be proud of Turk4n has much to be proud of Turk4n has much to be proud of Turk4n has much to be proud of Turk4n's Avatar
    Join Date
    May 2008
    Location
    4chan.org/g/
    Age
    20
    Posts
    3,836
    Blog Entries
    4

    Re: java:Tutorial

    Quote Originally Posted by Aroos View Post
    Thanks for nice share. It was really good.

    I need some more examples about multi dimensional arrays java . Could you explain and put some more examples about?

    THanks
    Sure, just view this thread, it has great information about multi dimensional arrays !
    Multidimensional Arrays
    Credit goes to Chili5

    Hatsune Miku ~❤❤❤
    初音ミク。~❤❤❤

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. JavaScript:Tutorial, Using Arrays
    By TcM in forum Javascript
    Replies: 25
    Last Post: 07-27-2009, 06:13 AM
  2. Python arrays...
    By Sir_Rimo in forum Python
    Replies: 3
    Last Post: 06-20-2007, 08:54 AM
  3. Arrays
    By clookid in forum PHP Tutorials
    Replies: 1
    Last Post: 01-11-2007, 08:30 PM
  4. Arrays
    By Sionofdarkness in forum C and C++
    Replies: 5
    Last Post: 07-26-2006, 05:35 PM
  5. Arrays in NET 2.0 or CLI Managed C++
    By Void in forum Managed C++
    Replies: 1
    Last Post: 07-18-2006, 07:57 PM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts