Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Array (of a class) memory(reference) comparison

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Array (of a class) memory(reference) comparison

    My goal is to sort an array of a class, for example myClass

    Sort the memory locations:
    For example if myClass[0] has a greater memorylocation than myClass[1] then i would like them to exchange place. Switch places are easy, but how do i find out what memorylocation is the greatest?

    this doesn't work, but you might get the idea of what i want to do:
    if(memorylocation of myClass[0] > memorylocation of myClass[1])
    //exchange memoryadresses

    for example: i want to change the memoryadresses below
    System.out.print(myClass[0]); -----> myClass@279febb9
    System.out.print(myClass[1]); -----> myClass@24db06de
    System.out.print(myClass[2]); -----> myClass@28db06de
    System.out.print(myClass[3]); -----> myClass@23db06de

    to this:
    System.out.print(myClass[0]); -----> myClass@23db06de
    System.out.print(myClass[1]); -----> myClass@24db06de
    System.out.print(myClass[2]); -----> myClass@279febb9
    System.out.print(myClass[3]); -----> myClass@28db06de


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Array (of a class) memory(reference) comparison

    The memory address/hashcode following the @ is a hex number. Look at the Integer class for a method to convert a String in base 16 to an int value that can be compared to other numbers.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Is it possible to reference Variables from another class
    By JoeBrown in forum Java Theory & Questions
    Replies: 4
    Last Post: February 22nd, 2012, 03:30 PM
  2. Array elements comparison
    By Pradeep_Parihar in forum Java Theory & Questions
    Replies: 1
    Last Post: December 10th, 2011, 09:45 AM
  3. Why is comparison of objects of Class implementing CharSequence undefined?
    By rsameera in forum Object Oriented Programming
    Replies: 1
    Last Post: September 4th, 2011, 02:30 PM
  4. Need help with array comparison
    By raidcomputer in forum Collections and Generics
    Replies: 4
    Last Post: November 17th, 2009, 01:55 PM
  5. Array comparison
    By subhvi in forum Collections and Generics
    Replies: 5
    Last Post: September 3rd, 2009, 03:56 AM