Results 1 to 3 of 3
  1. #1
    Dayanand is offline Member
    Join Date
    Feb 2011
    Posts
    61
    Rep Power
    0

    Default Arrays memory addresses

    package basics;

    public class Mgr
    {

    public static void main(String[] args)
    {
    int all[] = new int [10];
    System.out.println(all);
    System.out.println(all[1]);
    }
    }
    output
    [I@1242719c
    0

    Hi
    i want to know the memory addresses of each element in the array
    here i am printing System.out.println(all);

    if all is starting element`s memory address of the array all[].?
    then how to know the remaining elements memory addresses which are in the array all[]

    more ever the address [I@1242719c its keep on changing when ever i compile for the next time to [I@1242719c1,,,,i want to know the reason why it happens so

    Thanks in advance
    Daya
    Last edited by Dayanand; 03-04-2011 at 06:13 AM.

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,004
    Blog Entries
    7
    Rep Power
    20

    Default

    Java is not C (nor C++) and you can't have a 'memory address' from an object by just using Java but more important: why do you want such functionality? It isn't needed in Java.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default

    In addition that address can change during execution depending on what the garbage collector does. If it compacts the memory then it can shift where this array is held.

    So, to reiterate what Jos has said, why do you think you need to know this information?

Similar Threads

  1. Printing memory addresses and null values
    By Ben1 in forum New To Java
    Replies: 21
    Last Post: 10-11-2010, 05:05 PM
  2. Replies: 4
    Last Post: 08-01-2010, 09:25 AM
  3. Replies: 0
    Last Post: 04-15-2009, 02:49 AM
  4. Replies: 2
    Last Post: 12-07-2008, 06:13 PM
  5. how to read memory addresses
    By fred in forum New To Java
    Replies: 1
    Last Post: 07-24-2007, 01:59 AM

Posting Permissions

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