Arrays.sort() issue when Numbers are a string!

Hey guys -- here is my problem.
I am working on a TOP TEN SCORES mechanism for a trivia game. I have read in the score and the players name from a file. SO I have 2 different arrays topScores[] and topNames[] ---
Now if someone plays the game and has a higher score than the lowest score, they get to put their score and name in the file and replace the low score.
HOWEVER -- I do not know how to sort topSCORES[] and then make whatever sorted changes apply also to the topNAMES[] array.
SO I thought - HEY I will concatenate the topScores and topNames into a single String array. And then SORT! This sounded like a great idea until I realized that the following will happen:
100 tvance (first one)
1000 dvance (second score)
250 danderson (third score) !!!
See my problem? When I sort this way - it is sorting alphabetically so it will put a 1000 score before a 200-900 score! ---
**I hope I explained this adequately -- can someone help? Is there a way to sort the topScores array and have it also change the order of the topNames array as well?

Create a new class - HighScore, which has a highScore and a name?Yup. This technique even has a name: object-oriented programming!
Demo:
import java.util.*;
public final class HighScore implements Comparable<HighScore> {
    private final int score;
    private final String name;
    public HighScore(int score, String name) {
        if (name == null)
            throw new NullPointerException();
        this.score = score;
        this.name = name;
    public int getScore() {
        return score;
    public String getName() {
        return name;
    public int compareTo(HighScore that) {
        if (this.score < that.score)
            return -1;
        else if (this.score > that.score)
            return +1;
        else
            return this.name.compareTo(that.name);
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        else if (obj instanceof HighScore) {
            HighScore that = (HighScore) obj;
            return this.score == that.score && this.name == that.name;
        } else
            return false;
    public int hashCode() {
        return score ^ name.hashCode();
    public String toString() {
        return score + " " + name;
    //demo
    public static void main(String[] args) {
        HighScore[] top = {
            new HighScore(250, "danderson"),
            new HighScore(1000, "dvance"),
            new HighScore(100, "dvance")
        Arrays.sort(top);
        for(int i=0; i<top.length; ++i) {
            System.out.println(top);
If you are using an older version of Java (1.4 or earlier), the generics won't be
recognized. In that case the class definition would begin:
public final class HighScore implements Comparable {And the compareTo method would begin:
public int compareTo(Object obj) {
    HighScore that = (HighScore) obj;Good luck!

Similar Messages

  • Issue when stats are run

    Hi All,
    When we execute the stats we get the below error.Its a MSCS cluster enterpise portal oracle 10g
    C:\Documents and Settings\ql0adm>brconnect -u ql0adm/<pwd> -c -f stats -t ora
    dict_stats
    BR0801I BRCONNECT 7.00 (44)
    BR0252E Function NetShareGetInfo() failed for 'sapmnt' at location BrEnvProcess-
    89
    BR0253E errno 2310: This shared resource does not exist.
    BR0806I End of BRCONNECT processing: ceehwaio.log 2010-10-11 16.18.54
    BR0280I BRCONNECT time stamp: 2010-10-11 16.18.54
    BR0804I BRCONNECT terminated with errors

    >
    Ambarish annapureddy wrote:
    > HI Volker,
    >
    > You are a champ.I dont have anyother words to express.
    > The issue got resolved.We gave SAPEXE and SAPMNT.We faced issue when we used ops$ then i used system user and it went through.Before closing the thread i want to know how did you get the note.Thanks a ton again.
    Sorry,
    I did not come across this for a while
    Well it was not such an obvious search as for your message, but just from my memory of
    installing on MSCS and that there was something special to the brtools. So that knowlegde
    in behind, my search was "MSCS brtools" -> two hits -> one bingo
    Volker

  • How to Improve performance issue when we are using BRM LDB

    HI All,
    I am facing a performanc eissue when i am retriving the data from BKPF and respective BSEG table....I see that for fiscal period there are around 60lakhs records. and to populate the data value from the table to final internal table its taking so much of time.
    when i tried to make use of the BRM LDB with the SAP Query/Quickviewer, its the same issue.
    Please suggest me how to improve the performance issue.
    Thanks in advance
    Chakradhar

    Moderator message - Please see Please Read before Posting in the Performance and Tuning Forum before posting - post locked
    Rob

  • Select list with submit issue when they are referred in report region query

    I have a page with a reporting region. Same region also has 3 different list items and depending on the value selected in each item, the report is refreshed. All the 3 list items are "Select list submit with submit"
    Out of 3 items, 2 (say item2 and item3) are populated through dynamic LOV using the value in item1.
    Additionally, when I select a default "ALL" value in in item1, I ignore values in item2 and item3.
    With this background, I am a following issue:
    1. I select a value other than Default value in item1 which filters the report.
    2. Then I select some value in item2 which further shrinks the reports.
    3. Now if I go back to item1 and select the default "All" value, the report is not refreshed with the new values of item1, item2 and item3. But it still shows the report based on value of item2 that I selected in step2.
    How do I set the value of item2/item3 to null if value of item1 is default which is "All"
    Any word of advise will be a great help!
    Thanks,
    Girish

    Hi,
    Make two computations each with the computation text NULL; or
    Make one process with code like:
    BEGIN
    :P1_ITEM2 := NULL;
    :P1_ITEM3 := NULL;
    END;With the condition "Value of Item in Expression 1 = Expression 2"
    Expression 1: P1_ITEM1
    Expression 2: ALL
    (or whatever the return value of ALL is...remember that this is case sensitive)
    Mike

  • JDeveloper 12.c ListView issue when elements are repeated.

    Hi
    Using the ListView, and choosing the panel grid layout, if my view object has repeated rows, then the styles are not applied for those rows messing up the row (it doesn't display correctly, no height - width styles whatsoever). I have checked the source code generated and this is what I've found - This is for each element of my list. The ones that repeat (0 and 3) are the one with the issues. They should be treated as different records.
    <div id="r2:0:lv1:0:li1" class="xvl" data-afrrk="0">
    <div id="r2:0:lv1:0:li1" class="xvl" data-afrrk="0">
    <div id="r2:0:lv1:1:li1" class="xvl" data-afrrk="1">
    <div id="r2:0:lv1:2:li1" class="xvl" data-afrrk="2">
    <div id="r2:0:lv1:3:li1" class="xvl" data-afrrk="3">
    <div id="r2:0:lv1:3:li1" class="xvl" data-afrrk="3">
    If I explore "data-afrrk="0"" element, just one have style applied. And the same for data-afrrk="3".
    This is what I see:
    Well I couldn't insert an image. It is disabled.
    Regards

    Hi. I just used the drag and drop. It works fine when using panel group instead the panel grid layout.
    <af:listView value="#{bindings.UserPersonalInfo3.collectionModel}" var="item"
                     emptyText="#{bindings.UserPersonalInfo3.viewable ? 'No data to display.' : 'Access Denied.'}"
                     fetchSize="#{bindings.UserPersonalInfo3.rangeSize}" id="lv1" selection="single"
                     selectionListener="#{bindings.UserPersonalInfo3.treeModel.makeCurrent}">
          <af:listItem id="li1">
            <af:panelGridLayout id="pgl8">
              <af:gridRow marginTop="5px" height="auto" marginBottom="5px" id="gr1">
                <af:gridCell marginStart="5px" width="15%" id="gc1">
                  <af:panelGroupLayout id="pgl2" layout="horizontal">
                    <af:outputFormatted value="#{item.bindings.UserName.inputValue != null ? item.bindings.UserName.inputValue : 'NONE'}"
                                        id="of1"/>
                  </af:panelGroupLayout>
                </af:gridCell>
                <af:gridCell marginStart="5px" width="60%" id="gc2">
                  <af:panelGroupLayout id="pgl7" layout="horizontal">
                    <af:panelGroupLayout id="pgl3" layout="vertical" halign="left">
                      <af:panelGroupLayout id="pgl4">
                        <af:outputFormatted value="#{item.bindings.FirstName.inputValue}" id="of2"
                                            inlineStyle="font-size:medium;"/>
                        <af:spacer width="10" height="10" id="s1"/>
                        <af:outputFormatted value="#{item.bindings.LastName.inputValue}" id="of3"
                                            inlineStyle="font-size:medium;"/>
                      </af:panelGroupLayout>
                      <af:panelGroupLayout id="pgl5">
                        <af:outputFormatted value="#{item.bindings.JobName.inputValue}" id="of4"
                                            inlineStyle="font-size:small;"/>
                      </af:panelGroupLayout>
                    </af:panelGroupLayout>
                  </af:panelGroupLayout>
                </af:gridCell>
                <af:gridCell marginStart="5px" width="25%" marginEnd="5px" id="gc3">
                  <af:panelGroupLayout id="pgl6">
                    <af:outputFormatted value="#{item.bindings.OrganizationName.inputValue}" id="of5"/>
                  </af:panelGroupLayout>
                </af:gridCell>
              </af:gridRow>
            </af:panelGridLayout>
          </af:listItem>
        </af:listView>

  • ITunes Sorting Issue - By numbers? (not "track numbers")

    How can I get iTunes to sort using the defaulted numbers in List View. The header cannot be clicked in List View, but can in Grid View. Is there any way it can be clicked or tricked into sorting using them? It's very handy. Thanks.

    If you click on any column header, it will sort the entire library in numerical or alphabetical order based on the listing of whatever column header has been clicked on.
    So if you click on "Name", you will get:
    2 Minutes To Midnight - Iron Maiden - 9 of 16
    8 Mile Road - Grant Lee Buffalo - 9 of 14
    A Bad Night - Cat Stevens - 19 of 19
    Badlands - Bruce Springsteen - 1 of 10
    Classico - Tenacious D - 2 of 15
    etc.
    If you click on "Artist" then the exact same Library will be re-ordered as:
    Badlands - Bruce Springsteen - 1 of 10
    A Bad Night - Cat Stevens - 19 of 19
    8 Mile Road - Grant Lee Buffalo - 9 of 14
    2 Minutes To Midnight - Iron Maiden - 9 of 16
    Classico - Tenacious D - 2 of 15
    etc.
    By default, iTunes should be recognising the "Artist" column as the main sorting definer, with album track numbers being the secondary sorting consideration within artists.
    If for some reason your sorting order has fallen foul of this, then to get it back on track, firstclick on the "Track #" header, to sort your songs by track number: 1 of 10, 2 of 10, 3 of 10, etc. and then click on "Artist".
    This should get it back to how you want it.
    If this [still] isn't working for you, then you need to perhaps check that your songs are tagged correctly. Make sure that all tracks from the same album all have the track numbers filled in, in both the first and second fields in the "Track Number" spaces, ie: X of X.

  • Lookup issue when staging area diff from target

    Hi,
    I am using staging area different from target (csv file to database)
    Everything is working fine the source data is moved to target. The interface runs suiceessfuly.
    Now i want to add a lookup during transformation using a lookup table.
    When i do that using lookups in quick edit section, i am getting an error.
    When i run the interface, the C$ gets created in staging area - that is correct.
    However when inserting from staging to target, now the ODI searches for the C$ table in target area instead of the staging..
    Please help.
    Thanks,
    Rosh

    Hi
    1st thing you have to give the workschema for temp tables when creating physical schema in dataserver for target.
    Then you have to select the workschema in overview of interface as "staging different from target".
    After doing this when you will use predefined KM for the interface it will create temp tables in workschema.
    Now suppose you are not giving the workschma at the time of creating physical schema and you have selected "staging different than target" in interface.Here your C$ table will be created in your workschema but I$ table that is used by IKM is going to be created on target schema.So for this again you have change the IKM KM i.e. where to create I$ table (wokrschema) by selecting the corresponding logical schema.
    So its better you give the workschema at the time of creating physical schema.
    Here is the query to give privilege by the sys_dba
    Grant create any table to ODI_TEMP.
    Hope you got it
    (Please mark the answer as correct or helpful and close the thread)
    Thanks

  • Client access issues when mailboxes are mounted on a specific mailbox server

    One of our 3 mailbox servers gives us an error when mailbox databases are mounted on it.
    All web services are not functioning properly, there is an event log error for each web service web.config file saying file not found, If I open each web.config file and look at the line in question they all point to:
    <assemblies>
            <add assembly="Microsoft.Exchange.Security, Version=15.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
          </assemblies>
    Does anyone know what this is pointing at or what my server is missing?
    It is Exchange 2013 Sp1 RU7 as are my other 2 mbx servers which work fine...
    all pre-req's are installed as I double checked and no difference between the 3 mbx servers that I can see...
    ***Don't forget to mark helpful or answer***

    IIS error
    === Pre-bind state information ===<o:p></o:p>
    LOG: DisplayName = Microsoft.Exchange.Security, Version=15.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35<o:p></o:p>
    (Fully-specified)<o:p></o:p>
    LOG: Appbase = file:///C:/Program Files/Microsoft/Exchange Server/V15/ClientAccess/Autodiscover/<o:p></o:p>
    LOG: Initial PrivatePath = C:\Program Files\Microsoft\Exchange Server\V15\ClientAccess\Autodiscover\bin<o:p></o:p>
    Calling assembly : (Unknown).<o:p></o:p>
    ===<o:p></o:p>
    LOG: This bind starts in default load context.<o:p></o:p>
    LOG: Using application configuration file: C:\Program Files\Microsoft\Exchange Server\V15\ClientAccess\Autodiscover\web.config<o:p></o:p>
    LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet.config<o:p></o:p>
    LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.<o:p></o:p>
    LOG: Post-policy reference: Microsoft.Exchange.Security, Version=15.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35<o:p></o:p>
    LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/autodiscover/b455e468/cbaac37d/Microsoft.Exchange.Security.DLL.<o:p></o:p>
    LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/autodiscover/b455e468/cbaac37d/Microsoft.Exchange.Security/Microsoft.Exchange.Security.DLL.<o:p></o:p>
    LOG: Attempting download of new URL file:///C:/Program Files/Microsoft/Exchange Server/V15/ClientAccess/Autodiscover/bin/Microsoft.Exchange.Security.DLL.<o:p></o:p>
    LOG: Attempting download of new URL file:///C:/Program Files/Microsoft/Exchange Server/V15/ClientAccess/Autodiscover/bin/Microsoft.Exchange.Security/Microsoft.Exchange.Security.DLL.<o:p></o:p>
    LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/autodiscover/b455e468/cbaac37d/Microsoft.Exchange.Security.EXE.<o:p></o:p>
    LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/autodiscover/b455e468/cbaac37d/Microsoft.Exchange.Security/Microsoft.Exchange.Security.EXE.<o:p></o:p>
    LOG: Attempting download of new URL file:///C:/Program Files/Microsoft/Exchange Server/V15/ClientAccess/Autodiscover/bin/Microsoft.Exchange.Security.EXE.<o:p></o:p>
    LOG: Attempting download of new URL file:///C:/Program Files/Microsoft/Exchange Server/V15/ClientAccess/Autodiscover/bin/Microsoft.Exchange.Security/Microsoft.Exchange.Security.EXE.<o:p></o:p>
    ***Don't forget to mark helpful or answer***

  • Sorting issue when using DISTINCT

    Hi All,
    If we use distinct in a select query, does it sort the results by default?
    If so,Can anybody explain, why is it giving the results in sorted order?
    Thanks a lot...
    Regards,
    user569598

    It may or may not sort the results depending on the Oracle version and the precise access path chosen.
    If you want to guarantee that the results come in a sorted order, you have exactly one option. You must specify an ORDER BY clause.
    Various other approaches (such as adding a DISTINCT or doing a GROUP BY) may, under certain circumstances, sort the results as a side effect, but Oracle is perfectly free to introduce new optimizer options in future releases that do not have this side effect or to change query plans in a particular instance based on changing statistics in a way that eliminates this side effect.
    Justin

  • How can I change a string to a numeric when the numbers are separated by blank spaces?

    I would like to change a list of numbers in string to a list of number in numeric like in the attached vi. Unfortunately, the numbers are not separated by commas but by blank spaces. Which character can I use for the blank space?
    Ninskaya
    Attachments:
    readcommdelim.vi ‏19 KB

    Why don't you just use the Spreadsheet String to Array function instead. You can specify any delimiter you want. See the attached picture.
    Attachments:
    string_to_array.jpg ‏6 KB

  • Iteration Speed issue when Indexing 3D array wried to a while-loop

    Brief Description of my Program:
    I am working on the real-time signal generation by using LabView and DAQmx (PCI-6110 card). My vi reads the big data file (typically 8MB txt file containing about 400,000 samples (complex double precision). Then, the signal is pre-processed and I end up with a huge 3D array to feed while-loop (typically 3D array dimension is N x 7 x M where N & M >> 7). Inside the loop, that 3D array is indexed and processed before the results are written to the DAQmx outputs. I have a speed issue when indexing the large 3D array (i.e, 3D array having a large sub-array size). My while-loop could not run fast enough to top-up the DAQmx AO buffer (at the output rate of 96kHz). It could run faster only if I use smaller 3D array (i.e, smaller-sized sub-arrays). I do not quite understand why the size of 3D sub-array affects the rate of looping although I am indexing same sub-array size at each iteration. I really appreciate your comments, advices and helps.
    I include my 3D array format as a picture below.
    Question on LabView:
    How does indexing an 3D array which wires to the while-loop affect the speed of the loop iteration? I found that large dimension of sub-arrays in the 3D array slows down the iteration speed by comparing to indexing the same size of sub-array from smaller-sized sub-arrays of the 3D array to perform signal processing inside the while-loop. Why? Is there any other way of designing LabView Program to improve speed of iteration?
    attachment:

    Thank you all for your prompt replies and your interests. I am sorry about my attachment. But, I have now attached a jpg format image file as you suggested.
    I had read the few papers on large data handling such as "LabVIEW Performance and Memory Management". Thus, I had already tried to avoid making unnecessary copies of data and growing arrays in my while-loop. I am not an expert on LabView, so I am not sure if the issues I have are just LabView fundamental limitations or there are any other ways to improve the iteration speed without reducing the input file size and DAQ output rate.
    As you request, I also attach my top-level vi showing essential sections such as while-loop and its indexing. The attached file is as an image jpg format because the actual vi including Sub-VIs are as big as 3MB in total. I hope my attachment would be useful for anyone who would like to reply my question. If anyone would like to see my whole vi & llb files, I would be interesting to send it to you by an e-mail privately and thus please provide your e-mail address.
    The dimension of my 3D array is N x 7 x M (Page x Row x Column), where N represents number of pages in 3D array, and M represents the size of 1D array.  The file I am currently using forms 3D array of N = 28, & M = 10,731.  Refering to the top-level vi picture I attached, my while-loop indexes each page per iteration and wrap-around.  The sub-VI called "channel" inside the while-loop will further index its input (2D array) into seven of 1D arrays for other signal processsing.  The output from that "channel" sub-VI is the superposition of those seven arrays.  I hope my explaination is clear. 
    Attachement: 3Darray.jpg and MyVi.jpg
    Kind Regards,
    Shein
    Attachments:
    3Darray.jpg ‏30 KB
    MyVI.jpg ‏87 KB

  • Multiple selection causing issue when sorted

    I have an issue when using multiple selection along with sortable column. If certain rows are selected and then a column is sorted, selected rows remains as it is but data changes. Moreover sorting happens within the rows in the page and not across the table. Please provide me solution. Thank you
    <af:table value="#{bindings.CntTypecntItem.collectionModel}"
    var="row"
    rows="#{bindings.CntTypecntItem.rangeSize}"
    first="#{bindings.CntTypecntItem.rangeStart}"
    emptyText="#{bindings.CntTypecntItem.viewable ? 'No rows yet.' : 'Access Denied.'}"
    width="860" id="tblSearchIcLcResults"
    binding="#{SearchNAssign.tblSearchIcLcResults}">
    <f:facet name="selection">
    <af:tableSelectMany required="false"/>
    </f:facet>
    <af:column sortProperty="ctry"
    sortable="true"
    headerText="Country">
    <af:outputText value="#{bindings.countryName.inputValue}"/>
    </af:column>

    Hi,
    if you are on a POJO business service, make sure the primary key attribute is set for the PK attribute in the generated data control XML file. So if your entity is "Employees" then select "Employees.xml", open the Structure Window (ctrl-shift-s) and select the attribute that is the PK. In the property inspector,set he PrimaryKey property to true
    Frank

  • TreeSet vs Collection.Sort / Array.sort for Strings

    Gurus
    I am pondering weather to use TreeSet vs the Collections.sort / Array.sort for sorting Strings.
    Basically I have a list of Strings, i need to perform the following operations on these Strings
    1) Able to list Strings starting with a Prefix
    2) Able to list Strings Lexically greater than a String
    Any help would be greatly appreciated!
    Thanks a bunch

    SpaceShuttle wrote:
    Gurus
    I am pondering weather to use TreeSet vs the Collections.sort / Array.sort for sorting Strings.
    Basically I have a list of Strings, i need to perform the following operations on these Strings
    1) Able to list Strings starting with a Prefix
    2) Able to list Strings Lexically greater than a String
    Any help would be greatly appreciated!
    Thanks a bunchBig-O wise, there's no difference between sorting a list of N elements or inserting them one by one in a tree-set. Both take O(n*log(n)). But both collections are not well suited for looking up string that start with a certain substring. In that case you had better use a Patricia tree (or Radix tree).
    Good luck.

  • I'm using firefox 3.6.4 dutch. On some sites telephone numbers are just visible during 1 second, then they disappear. When refresing they are again visible during 1 second.

    I'm using firefox 3.6.4 dutch. On some sites telephone numbers are just visible during 1 second, then they disappear. When refresing they are again visible during 1 second.
    == This happened ==
    Every time Firefox opened

    Hello,
    the issue of phone numbers disappearing can be fixed by disabling the Skype add-on:
    #Go to Tools > Add-ons .
    #Find the Skype add-on in the list.
    #Click the Disable or the Uninstall button.
    #Restart Firefox.
    --Tobbi

  • When I drop a page into a second document the text and numbers are misaligned. How can I stop this?

    I have a master PDF that I am coping pages into from a sub-portion PDF document.  When I drop the new page in many characters (text and numbers) are misaligned on the recently added page and some characters have just vanished.  I tried converting to PDF/A Mode for one source document and PDF/X Mode for another that seemed to fix the issue.
    I'm wondering if there is a better better way, maybe some setting I can change in order to prevent my plain old PDFs from having this character jumbling?

    You very likely have fonts embedded in the source file that are not in the new file and that scrambles things. Why not just extract the page from the old document and then do an insert to see if that does the job. Extra work, but it might help identify the problem.

Maybe you are looking for