Sort a string :: Please help.

Hello Everyone,
I am having this very simple problem of sorting a String. please help.
     static String sortString(String str){
          List list = Arrays.asList(str);                    
          Collections.sort(list);
          for(int i=0, n=list.size();i<n;i++){
               System.out.println(","+ list.get(i));
The function is supposed to take a String and sort it & print it out. This should be simple. Where am I making mistakes? Please help!!

Hello Everyone,
I am having this very simple problem of sorting a String. please help.
     static String sortString(String str){
          List list = Arrays.asList(str);                    
          Collections.sort(list);
          for(int i=0, n=list.size();i<n;i++){
               System.out.println(","+ list.get(i));
               return str;
The function is supposed to take a String and sort it & print it out. This should be simple. Where am I making mistakes? Please help!!

Similar Messages

  • Pass username and password ADFS without using query string, Please help.

    pass username and password ADFS without using query string, Please help.
    I used query string , but it is unsecured to pass credentials over url, with simple tool like httpwatch , anyone can easily get the password and decrypt it.

    Hi,
    According to your post, my understanding is that you had an issue about the ADFS.
    As this issue is related to ADFS, I recommend you post your issue to the forum for ADFS.
    http://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=Geneva
    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us.
    Thank you for your understanding and support.
    Thanks,
    Jason
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
    [email protected]
    Jason Guo
    TechNet Community Support

  • Why can't I buy any app ? Iv tried creating a new Appel account ect but it says the same thing everytime . Sorry your payment was declined . How can I sort this ? Please help

    Why can't I buy any app ? Iv tried creating a new Appel account ect but it says the same thing everytime . Sorry your payment was declined . How can I sort this ? Please help

    - Try another payment method.
    - Contact iTunes
    Apple - Support - iTunes - Contact Us
    - Create a NEW account using these instructions. Make sure you follow the instructions. Many do not and if you do not you will not get the None option. You must use an email address that you have not used with Apple before.
    Creating an iTunes Store, App Store, iBookstore, and Mac App Store account without a credit card

  • Sorting and Searching String (Please help me)

    Hi, Could somn please be of any help here. I am trying to sort this string in alphabetical order and then search for data available but I am not makingprogress with the code. Does anyone have any advise or better still the code to solve this problem... This is hat I have at the moment
    import java.util.*;
    import java.io.PrintStream;
    import java.io.File;
    import java.io.FileNotFoundException;
    public class coursework2
         public static final int MAX_RECORDS = 20;
         public static String lastName[] = new String[MAX_RECORDS];
         public static String firstName[] = new String[MAX_RECORDS];
         public static String telNumber[] = new String[MAX_RECORDS];
         public static String emailAddress[] = new String[MAX_RECORDS];
         public static int read_in_file(String file_name)
              Scanner read_in;
              Scanner line;
              int record_count = 0;
              String record;
              try
                   read_in = new Scanner(new File(file_name));
                   // read in one line at a time
                   read_in.useDelimiter(System.getProperty("line.separator"));
                   while (read_in.hasNext())
                        // Test to see if there are too many records in the file
                        if (record_count == MAX_RECORDS)
                             System.out.printf("Only %d records allowed in file", MAX_RECORDS);
                             System.exit(0);
                        // read in record
                        record = new String(read_in.next());
                        // Split the record up into its fields and store in
                        // appropriate arrays
                        line = new Scanner(record);
                        line.useDelimiter("\\s*,,\\s*");
                        lastName[record_count] = line.next();
                        firstName[record_count] = line.next();
                        telNumber[record_count] = line.next();
                        emailAddress[record_count] = line.next();
                        // Increment record count
                        record_count++;
              catch (FileNotFoundException e)
                   e.printStackTrace();
              return record_count;
         public static void write_out_file(int no_of_records, String filename)
              PrintStream write_out;
              int counter;
              try
                   // Create new file
                   write_out = new PrintStream(new File(filename));
                   // Output all reacords
                   for(counter = 0; counter < no_of_records; counter++)
                        // Output a record
                        write_out.print(lastName[counter]);
                        write_out.print(",,");
                        write_out.print(firstName[counter]);
                        write_out.print(",,");
                        write_out.print(telNumber[counter]);
                        write_out.print(",,");
                        write_out.println(emailAddress[counter]);
                   // Close file
                   write_out.close();
              catch (FileNotFoundException e)
                   e.printStackTrace();
         // Your 'functions' go here
         //This code sorts out the record after loaded into alphabetical order using
         //the selection sort method
         public static void sort()
         // Your 'main' code goes here
         //The code below uses a binary search method to search for record because
         //record have been sorted and this would make search faster and more efficient
         public static boolean linearSearch(String strFirstName, String strLastName)
              //Set-up data_input and declare variables
              //This linear search searches for record in the contact application.
              //Search for a record using surname only
                   int i = 0;
                   boolean found = false;
                   while (!found && i < lastName.length)
                        if(strFirstName.equals("") && strLastName.equals(""))
                             return true;
                        if(lastName.equalsIgnoreCase(strLastName)){
                   //List records from surname only
                   System.out.println("Enter your search criteria (last name only):");
                        System.out.print(lastName[i] +     "\t" + firstName[i] + "\t" + telNumber[i] +"\t" + emailAddress[i]);
                        System.out.println("");
                        if (lastName[i].compareTo(strLastName) == 0)
                             //Compare the last name values and type to make sure they are same.
                             found = true;
                                  i++;
                                  System.out.print(lastName[i] +     "\t" + firstName[i] + "\t" + telNumber[i] +"\t" + emailAddress[i]);
                                       System.out.println("");
                             return found;
              //Search for a record using first name only
         public static void main(String[] args)
              // Set-up data input
              Scanner data_input = new Scanner(System.in);
              // Declare Variables
              int number_of_records;
              String filename;
              int counter;
              // Get filename and read in file
              System.out.print("Enter the masterfile file name: ");
              filename = data_input.next();
              number_of_records = read_in_file("data2.dat");
              //Get new filename and write out the file
              System.out.print("Enter new masterfile file name: ");
              filename = data_input.next();
              //System.out.println("Enter your search criteria (first or last name):");
              linearSearch("*", "");
    Am very sorry this is long, the file should be sorted after it is loaded and I have that, You can make up some data with last ane, first name, tel and email to show me an example. Thanks alot
    Joseph

    Hi Monica, Thanks for you patience with me.
    I have tried writing a selection sort method but am having some errors. Could you kindly have a lookand correct me please.
    This is the code i wrote
    public static void selectionSort(Comparable [] data)
              String strFirstName;
              String strLastName;
              Comparable temp;
              for(int i = 0; i < lastName.length; i++)
                   lastName = index;
                   for (int j = i; j < lastName.length; j++)
                        if (lastName[j].compareTo(lastName) < 0)
                             lastName[j] = lastName[i];
                   //Swap the string values
                   temp = lastName[j];
                   lastName[j] = lastName[i];
                   lastName[i] = temp;
    As you requested, below are 4 error messages I had
    E:\coursework2.java:101: cannot find symbol
    symbol : variable index
    location: class coursework2
                   lastName = index;
    ^
    E:\coursework2.java:107: cannot find symbol
    symbol : variable j
    location: class coursework2
                   temp = lastName[j];
    ^
    E:\coursework2.java:108: cannot find symbol
    symbol : variable j
    location: class coursework2
                   lastName[j] = lastName[i];
    ^
    E:\coursework2.java:109: incompatible types
    found : java.lang.Comparable
    required: java.lang.String
                   lastName[i] = temp;
    ^
    4 errors
    JCompiler done.
    JCompiler ready.
    Joseph

  • Problem in comparision of two strings.please help..

    I am retriving a string password from database and another string from html(user entered one).when i am printing those two strings its printing same strings.But whenever i am comparing strings and printing its not showing equal it is printing as false.what might be the reason.please help me regarding this.Thank you in advance.My cosing is as follows:
    while(rs.next())
    pwd=rs.getString("password");
    System.out.println("pmfg is..."+pwd);
    System.out.println("first string..."+pwd);
    System.out.println("second string..."+loginpwd);
    if(pwd.equals(loginpwd))
    System.out.println("true.....");
    else
    System.out.println("false....");

    once you got two string objects ......forget for where they are comming (database or html0 ....focus on those objects ....do the following
    1) use trim() function on both strings which removes the whitespaces from front and end
    2) use equalsIgnoreCase
    if the problem still persists ....then forget your code and sue the SUN people

  • Sort Not working - Please help

    Hello,
      I have design2003 parameter. Im displaying table with following logic. Problem is it is not activating SORT icon thats comes in table header text line which sorts the column. What could be wrong? Please help.
    <htmlb:tableView id              = "table_prod_cat"
                             design          = "alternating"
                             fillUpEmptyRows = "true"
                             headerText      = "Category_List"
                             headerVisible   = "true"
                             onRowSelection  = "prod_cat_rowselection"
                             selectionMode   = "none"
                             table           = "<%= lt_prod_cat_list %>"
                             visibleRowCount   = "<%= l_sprec_display %>"
                             width           = "100%" >
               <htmlb:tableViewColumns>
                <%-- Product Category ID --%>
                <htmlb:tableViewColumn columnName  = "product_cat"
                                       onItemClick = "prod_cat_id_itemclick"
                                       width       = "80"
                                       sort        = "X"
                                       title       = "<B>Category</>"
                                       type        = "link" />
                <%-- Product Category Description --%>
                <htmlb:tableViewColumn columnName = "CATEGORY_TEXT"
                                       title      = "<B> Category Text</>"
                                        sort      = "X"
                                        width      = "200" />
                <htmlb:tableViewColumn columnName = "PRODUCT_GRP"
                                       title      = "<B>Product Group</>"
                                        sort      = "X"
                                       width      = "200" />
                <htmlb:tableViewColumn columnName = "PRODUCT_SGRP"
                                       title      = "<B>Product Sub-Group</>"
                                        sort      = "X"
                                       width      = "200" />
              </htmlb:tableViewColumns>
             </htmlb:tableView>

    Ajay,
    You should use sort = "server" or sort = "none" .
    sort     -               Use this attribute to activate sorting for the
    individual rows and to determine who is responsible for the sorting.
    NONE (default, there is no sorting), SERVER (HTMLB carries out the
    sorting) and APPLICATION (the application carries out the sorting) If
    you specify SERVER, you should also set the attributes keyColumn and
    onHeaderClick.
    I have changed your code..use this code and let me know if you get any issue.
    <htmlb:tableView id = "table_prod_cat"
    design = "alternating"
    fillUpEmptyRows = "true"
    headerText = "Category_List"
    headerVisible = "true"
    onRowSelection = "prod_cat_rowselection"
    selectionMode = "none"
    <b>sort          = "server"</b>
    table = "<%= lt_prod_cat_list %>"
    visibleRowCount = "<%= l_sprec_display %>"
    width = "100%" >
    <htmlb:tableViewColumns>
    <%-- Product Category ID --%>
    <htmlb:tableViewColumn columnName = "product_cat"
    onItemClick = "prod_cat_id_itemclick"
    width = "80"
    <b>sort = "true"</b>
    title = "<B>Category</>"
    type = "link" />
    <%-- Product Category Description --%>
    <htmlb:tableViewColumn columnName = "CATEGORY_TEXT"
    title = "<B> Category Text</>"
    <b>sort = "true"</b>
    width = "200" />
    <htmlb:tableViewColumn columnName = "PRODUCT_GRP"
    title = "<B>Product Group</>"
    <b>sort = "true"</b>
    width = "200" />
    <htmlb:tableViewColumn columnName = "PRODUCT_SGRP"
    title = "<B>Product Sub-Group</>"
    <b>sort = "true"</b>
    width = "200" />
    </htmlb:tableViewColumns>
    </htmlb:tableView>
    Thanks!
    Lakshmikandh<b></b>
    Message was edited by:
            Lakshmikandh Chinnasamy

  • Need Help to delet sort key! Please help!

    Hi,
    I have a problem in the following program.
    Source Code:
    t-belnr  = bsid-zuonr.
    SPLIT t-belnr at '#' into wk_belnr wk_x_belnr.
    CLEAR t-belnr.
        t-belnr  = wk_belnr.
        t-xblnr  = bsid-belnr.
        IF t-belnr NE space.
          s-belnr      = t-belnr.
        ELSE.
          t-belnr      = t-xblnr.
          s-belnr      = t-xblnr.
        ENDIF.
    IF t-xblnr NE space.                                    "WD041005a
          s-xblnr      = t-xblnr.                               "WD041005a
        ELSE.                                                   "WD041005a
          s-xblnr      = t-belnr.                               "WD041005a
        ENDIF.                                                  "WD041005a
        WHILE s-xblnr(1) EQ '0'.                            "INS MG130606
          SHIFT s-xblnr LEFT.                               "INS MG130606
        ENDWHILE.                                "INS MG130606
    In the final ALV.
    If first colum (t-zuonr) (sort key for the document )is blank, the document need to be deleted.
    Question:
    How can I write the code to deleted the t-zuonr when it is space?
    Please help!!!
    Thank you!!

    Try as below:
    DELETE <itab> WHERE <fld> IS INITIAL.
    i.e
    DELETE t WHERE zuonr IS INITIAL.
    Kind Regards
    Eswar

  • Converting a long to a string  (PLEASE HELP)

    I am trying to convert a long to a string so that I can put it into a vector. I have this:
    long fileSize = 0;
    String fileModDate = null;
    Vector fileList = new Vector();
         ~~~~~~~
    File [] files = myDir.listFiles();
    for (int i = 0; i<files.length; i++){
    fileSize = files.length();
    String s = fileSize.toString();
    //do the same for the mod date
    fileModDate = files[i].lastModified();
    When i try this, i get an error that long can not be dereferenced. Can anyone please help?

    There are two ways to solve this problem. You are trying to convert a primative type to a string without using its wrapper function (Long). So if you created a long variable as a (Long) object you could call its toString() method and this would work...
    The other way is to simply use the static method in the String class valueOf(long) as follows:
    String longString = String.valueOf(i);Hope this helps.
    Mark

  • Apple mail changing sort function. Please HELP.

    After a recommended update early last week,email keeps changing sort function. I set for date and keeps changing it to subject.
    PLease help repair this.
    thanks,
    don
    Don

    Hi Carlo,
    My Mail seems to work now.
    I should have done a screen capture to show you something.
    When I was about to send the message in Mail, a notice came up:
    It had 2 mail accounts:
    1. Mail
    2. my new e-mail address
    I think I pressed  Mail (if I remember).
    However, when I just sent another test message, there was no window warning coming up.
    Also, the "new Mail account" has nothing in it like the one that I deleted.
    The one that I deleted had lots of material (messsage, sent message, saved messages etc...) but nothing critical.
    I can live with that.
    The critical point will be when I go to a site and when I want to send a messafge, my Apple Mail account window opens.
    So far, your solution has worked even if the second part of your instructions could not be followed.
    Thanks again,
    Stacey

  • My ibook is "sort-of" dead" please help.

    after installing a third-party application, my computer started acting up, Parts of the picture would stop and just go black...things just got worse; Now the computer does turn on, but I dont hear the start up noise, all I hear is the fan running and the CD-Rom running as well. No picture. Im not sure if its a virus, or something worse. Ive tried resetting the pram and the pmu, I tried to boot up from the cd-rom ( which is now stuck in there ) Please help.
    iBook g4   Mac OS X (10.4.1)  

    After leaving my ipod hooked up to my computer for most of the day yesterday and resetting it a couple times, it actually turned on and started working. But the battery died almost immediately, so I am guessing it is the battery ... maybe?
    Any thoughts on how to go about getting a new battery? I am not great with technology and don't even see how to open the ipod so that the battery can be replaced.
    I appreciate any help!!
    Thanks!

  • Compairing strings please help

    how would i compare this string to an int:
    if(response.equals (1))
                                            System.out.println("good choice");
         else
                                            System.out.println("please enter 1 , 2 ,3 as your answer");
         }

    At the risk of stating the obvious, your not comparing strings.
    if(response.equals(1) ) // is wrong!
    it should be
    if ( response.equals("1") )
    It might help if you read the documentation on the equal() method in java.lang.String

  • Compilation Error while using string (Please help)

    Hi,
    I am using "Sun WorkShop Compiler C++ SPARC Version 5.000". Compiling code which contains a "string variable" throws the following error:
    "/opt/WS5/SC5.0/include/CC/./new", line 32: Error: The prior declaration for ope
    rator new(unsigned) has no exception specification.
    "/opt/WS5/SC5.0/include/CC/./new", line 34: Error: The prior declaration for ope
    rator delete(void*) has no exception specification.
    "/opt/WS5/SC5.0/include/CC/./new", line 36: Error: The prior declaration for ope
    rator new[](unsigned) has no exception specification.
    "/opt/WS5/SC5.0/include/CC/./new", line 38: Error: The prior declaration for ope
    rator delete[](void*) has no exception specification.
    4 Error(s) detected.
    The command used for compilation is :
    /opt/WS5/bin/CC -compat=4 -I/opt/WS5/SC5.0/include/CC -features=%all try.cpp
    Would help if I could get some comments on the above.
    Thanks and Regards,
    M Shetty

    There is a requirement that I use the Workshop 5.0
    compilere with option "-compat=4".
    The program I am trying to compile contains:
    #include <string>
    int main()
    string test = "aaa";
    return 0;
    There is no "string" in "-compat=4". You need to
    do something like this:
    // --- start test.cc ---
    #include <rw/cstring.h>
    int main()
    RWCString test = "aaa";
    return 0;
    // --- end test.cc ---
    CC -compat=4 -library=rwtools7 test.cc

  • URGENT!! Strings - Please help

    Hi
    I am urgently requiring help here. Any help would be greatly appreciated.
    I have a string:
    <clip clipID="{F46F8F95-DB46-4ECE-A44E-5906C7CC60EE}" originalFileName="009033d.rm"
    I need to find the string inside that starts with the first { and ends with the last }
    How do I do this??
    Thanks

    // Escape characters "\" only for this example
    String origString = "<clip clipID=\"{F46F8F95-DB46-4ECE-A44E-5906C7CC60EE}\" originalFileName=\"009033d.rm\"";
    String braketString = origString.substring(origString.firstIndexOf('{') + 1, origString.lastIndexOf('}'));I had to put escape characters in this example since there are quotes in the string. You won't have to worry about that, since I imagine you're getting the string from parsing some page content.
    Hope that helps,
    Mike

  • I can't get photos sorted in order, please help

    Hi,
    As the title says when I sync my photos to my iphone (and ipad) they are not in the same order as on my Mac. I've done a bit of research and I've found out that the iDevices sort photos by date rather than by name if you sync from a folder. However, I've also seen that the iDevices should mirror the way they appear in iphoto if you sync from this. Well I created all new folders in iphoto on my mac and synced with that but the photos are still out of order. Is there any way I can get them in order?
    Cheers.

    Try removing the Adobe DLM from your extensions in firefox. It will ask you to restart firefox. After restarting the pdf files should show in your browser as usual. This worked for me.

  • EVERYTHING'S GONE...sorta...PLEASE HELP!!!!

    Greetings.
    Tonight, as I walked home from work listening to my relatively new (and nearly full) 40GB iPod (which was just sitting in my pocket) as always, the music stopped. The iPod looked fine, but when I went to start playing music again, it skipped from song to song in the playlist (without playing any of them) and then went back to the main menu. I tried resetting it, but it wouldn't reset. When I got home, I plugged it into my computer. Suspiciously, iTunes didn't launch automatically. And when I opened iTunes, it asked me if I want to set up my new iPod! I hit cancel and ejected it, and now all the playlists and music files are gone. iTunes also says that it's empty (no song files show up when I select the iPod icon), but also says that more than 36 GB are used...so I know the music is still in there!
    What does all of this mean? Why aren't my song files showing up anymore? I've only had this iPod about a month--it was a warranty replacement for one that died--and only recently finished rebuilding all of my playlists and everything. Can I get it all back? Why did this happen? If I restore it and start from scratch--besides being unbelieveably aggravating--how do I know it won't just happen again?
    Thanks in advance for any help or advice...
    iBook   Mac OS X (10.3.9)  

    Do you keep all your music in iTunes? If so, then it shouldn't be a problem to erase the iPod, as everything will be restored again. If you manually put songs on your iPod, however, then you'll probably want to retrieve the files before such drastic measures (it sounds like something happened to the iPod's database, which won't affect the files still residing in the hard drive). Download a third-party iPod extraction utility (iPodRip is quite nice, though it may not work if the iPod database is corrupted) and copy the songs into iTunes, then restore the iPod and re-sync.
    For future reference, you posted in the wrong forum; there are no 40GB Fifth Generation iPods.

Maybe you are looking for