Thread: [asking] arrays?

Results 1 to 6 of 6
  1. #1 [asking] arrays? 
    Registered Member
    Join Date
    Apr 2009
    Posts
    57
    Thanks given
    0
    Thanks received
    0
    Rep Power
    1
    is arrays way way better? because i dont know how to use arrays or anything. My friend told me it will be less laggy and its better than using the "if" statement and stuff? is this true??
    Reply With Quote  
     

  2. #2  
    Registered Member
    PSNB's Avatar
    Join Date
    Aug 2009
    Posts
    885
    Thanks given
    8
    Thanks received
    103
    Rep Power
    590
    Arrays are used to store a collection of objects.

    Code:
    Player[] players = new Player[10];
    is a collection of players. Each player can be accessed via
    Code:
    Player p = players[index];
    index being the position of the player in the array. An array starts at index 0, and ends at index size - 1.

    If you didn't use an array for this, you'd end up having something like this

    Code:
    Player player1 = new Player();
    Player player2 = new Player();
    Player player3 = new Player();
    Player player4 = new Player();
    Player player5 = new Player();
    Player player6 = new Player();
    Player player7 = new Player();
    Player player8 = new Player();
    Player player9 = new Player();
    Player player10 = new Player();
    If you want to know more about arrays, I would advise reading This page.
    Reply With Quote  
     

  3. #3  
    Registered Member
    Join Date
    Apr 2009
    Posts
    57
    Thanks given
    0
    Thanks received
    0
    Rep Power
    1
    Quote Originally Posted by PSNB View Post
    Arrays are used to store a collection of objects.

    Code:
    Player[] players = new Player[10];
    is a collection of players. Each player can be accessed via
    Code:
    Player p = players[index];
    index being the position of the player in the array. An array starts at index 0, and ends at index size - 1.

    If you didn't use an array for this, you'd end up having something like this

    Code:
    Player player1 = new Player();
    Player player2 = new Player();
    Player player3 = new Player();
    Player player4 = new Player();
    Player player5 = new Player();
    Player player6 = new Player();
    Player player7 = new Player();
    Player player8 = new Player();
    Player player9 = new Player();
    Player player10 = new Player();
    If you want to know more about arrays, I would advise reading This page.
    so is it still stable to use "if this and that"??
    Reply With Quote  
     

  4. #4  
    Registered Member
    PSNB's Avatar
    Join Date
    Aug 2009
    Posts
    885
    Thanks given
    8
    Thanks received
    103
    Rep Power
    590
    Quote Originally Posted by slim811shady View Post
    so is it still stable to use "if this and that"??
    Arrays and if/else statements have absolutely nothing to do with one another.
    Reply With Quote  
     

  5. #5  
    Banned

    Join Date
    Apr 2008
    Age
    34
    Posts
    206
    Thanks given
    0
    Thanks received
    3
    Rep Power
    0
    array lists > arrays > single vars

    though, using array-list iterators is WAY slower then using old-school looping. (I've tested this and speed goes from 700ms old-school to over 2500ms using the iterator for aprox 2 million records)
    Reply With Quote  
     

  6. #6  
    Professional Java Developer

    Rainex's Avatar
    Join Date
    Jan 2010
    Age
    28
    Posts
    667
    Thanks given
    102
    Thanks received
    32
    Rep Power
    77
    Quote Originally Posted by slim811shady View Post
    is arrays way way better? because i dont know how to use arrays or anything. My friend told me it will be less laggy and its better than using the "if" statement and stuff? is this true??
    It is better than using if statements, because they also have println's in em, but arrays are neater, and less space, etc. i made a few tutorials on em, check em out.
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

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


User Tag List

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