Results 1 to 3 of 3
  1. #1
    parthpatel is offline Member
    Join Date
    Feb 2010
    Posts
    2
    Rep Power
    0

    Default Arrays.Sort usage

    If I am using Arrays.sort with custom comparator over references of objects of my custom class, then is there anyway to replace the contents of the objects while sorting instead of just rearranging the references of objects

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

    Default

    Quote Originally Posted by parthpatel View Post
    If I am using Arrays.sort with custom comparator over references of objects of my custom class, then is there anyway to replace the contents of the objects while sorting instead of just rearranging the references of objects
    Why do you want to do that? On average (or always?) it is much cheaper to rearrange the references than to swap the content of all the objects.

    kind regards,

    Jos

  3. #3
    parthpatel is offline Member
    Join Date
    Feb 2010
    Posts
    2
    Rep Power
    0

    Default

    I want to keep the array spatially aligned because it contains more than 1000000 elements and normally when element i is under consideration, elements around i are used multiple times. So, if the array is aligned then it might improve the performance.

    Parth

Similar Threads

  1. Using Merge Sort to sort an ArrayList of Strings
    By coldfire in forum New To Java
    Replies: 3
    Last Post: 03-13-2009, 01:03 AM
  2. usage of Hashtable
    By venu2807 in forum New To Java
    Replies: 4
    Last Post: 01-27-2009, 03:36 AM
  3. Replies: 2
    Last Post: 12-07-2008, 06:13 PM
  4. How to sort 2 arrays together
    By masaka in forum New To Java
    Replies: 13
    Last Post: 05-21-2008, 04:36 AM
  5. How to sort a list using Bubble sort algorithm
    By Java Tip in forum Algorithms
    Replies: 3
    Last Post: 04-29-2008, 08:04 PM

Posting Permissions

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