Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.help > #1112

Re: How to sort String array A based on int array B

From "Thee Chicago Wolf [MVP]" <.@.>
Newsgroups comp.lang.java.help
Subject Re: How to sort String array A based on int array B
Date 2011-09-23 08:51 -0500
Organization .
Message-ID <822p77tjmlsdrp2r7so1ko70igu9fascn6@4ax.com> (permalink)
References <1k2n77ltdv7ml661pa9a2g63j8q5l1c66g@4ax.com> <j5gdcf$ldp$1@dont-email.me>

Show all headers | View raw


>On 9/22/2011 12:31 PM, Thee Chicago Wolf [MVP] wrote:
>
>> The trouble I am having is sorting array B based on array A.
>
>
>I don't doubt that.  I'm having trouble understanding what "based on" 
>means here.  Can you elaborate?  What actual operation do you want to 
>preform on A and B, based on what criteria?

Ok, after reading my post I can see that I was not quite as clear as I
could have been.

So I have two arrays: A and B. Array A is an int array (I think I had
it backwards in my original description) and array B is a String
array. Array A is already ordered from 1 - 6 in ascending order and is
basically a rank order with 1 being most popular, 2 =  less popular
than 1, 3 = less so than 2, etc. Array B is the artist info,
scrambled, but each artist is defined by their appropriate popularity
with a #_ naming convention preceding the artist name and song title.
I figured that array B had to have some defining characteristic about
it else there would be no way to order a bunch of String info to a
corresponding rank without knowing the current artist ranking.

Thusly:

(Array A)
int[] rank = {1,2,3,4,5,6};

(Array B)
String[] artist = {"6_artist_song",
"4_artist_song",
"1_artist_song",
"3_artist_song",
"2_artist_song",
"5_artist_song"};

So array A is already sorted and array B is scrambled (read:
unsorted). Array B, however, does have the ranking for the artist
preceding it (i.e., 6_) and just needs to be sorted based on the
ranking (read: order) of array A.

Since array A is int and array B is String I figured I could do
something like (Integer.valueOf(charAt(artist[i])) (or would it be
(Integer.valueOf(charAt(0(artist[i]))) to just check the first
character of that index item against the first index item of array A.
And so if the values match, the index item of array B stays and we go
on to the next one and compare. If they don't match, we test the next
item of array B. So in the case of the above, it isn't until I get to
index 2 of array B that I get a corresponding match to index 0 of
array A. That's at least how I figured it should work in my head. ^_^
Is that a bit more clear on what I want to do? Cheers.

- Thee Chicago Wolf [MVP]

Back to comp.lang.java.help | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

How to sort String array A based on int array B "Thee Chicago Wolf [MVP]" <.@.> - 2011-09-22 14:31 -0500
  Re: How to sort String array A based on int array B markspace <-@.> - 2011-09-22 15:38 -0700
    Re: How to sort String array A based on int array B "Thee Chicago Wolf [MVP]" <.@.> - 2011-09-23 08:51 -0500
      Re: How to sort String array A based on int array B Patricia Shanahan <pats@acm.org> - 2011-09-23 07:23 -0700
        Re: How to sort String array A based on int array B "Thee Chicago Wolf [MVP]" <.@.> - 2011-09-23 10:51 -0500
          Re: How to sort String array A based on int array B Patricia Shanahan <pats@acm.org> - 2011-09-23 09:59 -0700
            Re: How to sort String array A based on int array B "Thee Chicago Wolf [MVP]" <.@.> - 2011-09-23 14:31 -0500
              Re: How to sort String array A based on int array B Patricia Shanahan <pats@acm.org> - 2011-09-23 12:39 -0700
              Re: How to sort String array A based on int array B "Charles Hottel" <chottel@earthlink.net> - 2011-09-23 17:42 -0400
                Re: How to sort String array A based on int array B "Thee Chicago Wolf (MVP)" <.@.> - 2011-09-23 20:27 -0500
                Re: How to sort String array A based on int array B Patricia Shanahan <pats@acm.org> - 2011-09-23 18:39 -0700
                Re: How to sort String array A based on int array B "Thee Chicago Wolf (MVP)" <.@.> - 2011-09-26 08:37 -0500
                Re: How to sort String array A based on int array B Patricia Shanahan <pats@acm.org> - 2011-09-26 08:04 -0700
                Re: How to sort String array A based on int array B "Thee Chicago Wolf [MVP]" <.@.> - 2011-09-27 13:47 -0500
                Re: How to sort String array A based on int array B "Thee Chicago Wolf [MVP]" <.@.> - 2011-09-27 13:59 -0500
                Re: How to sort String array A based on int array B Lew <lewbloch@gmail.com> - 2011-09-27 12:25 -0700
                Re: How to sort String array A based on int array B Lew <lewbloch@gmail.com> - 2011-09-26 09:00 -0700
                Re: How to sort String array A based on int array B "Charles Hottel" <chottel@earthlink.net> - 2011-09-23 23:31 -0400
                Re: How to sort String array A based on int array B "Thee Chicago Wolf (MVP)" <.@.> - 2011-09-26 08:29 -0500
  Re: How to sort String array A based on int array B Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-09-22 22:28 -0400
    Re: How to sort String array A based on int array B "Thee Chicago Wolf [MVP]" <.@.> - 2011-09-23 09:13 -0500
      Re: How to sort String array A based on int array B Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-09-23 20:45 -0400
  Re: How to sort String array A based on int array B Roedy Green <see_website@mindprod.com.invalid> - 2011-09-23 02:28 -0700
    Re: How to sort String array A based on int array B "Thee Chicago Wolf [MVP]" <.@.> - 2011-09-23 09:14 -0500
  Re: How to sort String array A based on int array B Roedy Green <see_website@mindprod.com.invalid> - 2011-09-25 00:46 -0700

csiph-web