Urgent help! question about list.toStirng()?

currently, i am working on a word counter programe, i stored each word and it's corresponding occurrence in a linkedlist. now i need to sort the list in the decreasing order of occurrence.
and the output would look like this:
not 2
a 2
i 1
am 1
girl 1
yet 1
woman 1
but the output so far i got looks like the following:
[not   2, a   2, i   1, am   1, girl   1, yet   1, woman   1]
and i know it becasue i uesed the "list.toString()"method. the question is how can i convert this format to the previous one or i could reach it in someway else?would anyone give me some tips?
the following code is i used for sorting:
public String results() //Compare the occurrences of  every two words in the list and reorder each node of
  {                       //the list in decreasing order of it's corresponding occurrence
       String str = "";
       ListIterator iter = list.listIterator();
       int length = list.size();
       int i,j;
       int count1, count2;
       WordNode temp1, temp2;
      for(i = 0; i < length-1; i++)
            for(j = i + 1; j<length; j++)
               temp1 = (WordNode)list.get(i);
               temp2 = (WordNode)list.get(j);
               count1 = temp1.getCount();
               count2 = temp2.getCount();
               if(count1 < count2)
                    list.remove(i);
                    list.add(i,temp2);
                    list.remove(j);
                    list.add(j,temp1);
      str = list.toString(); //Call the toSting() method in WordNode class to get each word and it's occurrence
      return str;
  }much appreciated.

Hi there,
The problem you have here is that you are not separating the distinct phases of your program. These are:
- build the sorted list
- print report
Thus, if I had to write the code below, I would change your results by two methods:
List sortedResult = sortWords();
printReport(sortedResult);
My sortWords() would be your results(), except that I would return list at the end, not list.toString().
Then, I would have all the flexibility in the world inside my printReport( List ) method. As a start, it would probably look like this:
public void printReport(List aList) {
  Iterator iter = list.iterator();
  while(iter.hasNext()) {
    System.out.println(iter.next());
}Regards,
Manuel Amago.

Similar Messages

  • Urgent - help question on sending http instead of https

    I'm trying to dump out my http wrapper: I'm trying to set send http instead of https so I can dump the wrapper.
    currently my code does the following for https determination. i read from a configuratioin file to see if i should set https or http
    question) Do i need an else section to cover non https?
    If so, what do i need to set for http properties.
    // check if https is wanted
    // yes - send https
    String useHttps = cf.get("useHttps", "true");
    if (useHttps.equals("true")) {
    logger.debug(classMethod + "https mode=" + useHttps);
    System.setProperty(
    "java.protocol.handler.pkgs",
    "com.sun.net.ssl.internal.www.protocol");
    // make provider and/or protocol configurable?
    Security.addProvider(
    new com.sun.net.ssl.internal.ssl.Provider());
    }

    resolved - don't need help anymore on it

  • Please help: question about eclipse & xerces

    hi,
    i have eclipse 3.0 and am trying to get the xerces java package (ver 2.6.2) to work for it. i downloaded xerces from this link: http://www.apache.org/dist/xml/xerces-j/
    there are so many different files in there, i'm not entirely sure if you download everything or just one. anyway, the one i downloaded was the fourth one down, called xerces.j.bin.2.6.2.zip (5.6m in size).
    i've unzipped it, but am unsure how i go about configuring eclipse 3.0 so that i can import and make use of xerces in my java apps. could anyone who has experience with this please help me?
    thanks,
    ramsey

    it's OK guys, took me ages but i got it sorted.

  • [Urgent] Some questions about Oracle Portal 10g - 11g upgrade

    Dear friends,
    We are under doing upgrading assessment of Oracle Portal from 10g to 11g. After reviewed the 'upgrading guide', we still have some questions as below:
    1. Whether the 'Instant Portal' feature remain in Oracle Portal 11g? If yes, how to migrate the Instant Portal 10g sites? If no, any workaround?
    2. Whether the old 10g Page Group and Pages will be still available after 11g upgrade? Also can customer import the old 10g transportset into Portal 11g?
    3. How about the customized Portal 10g objects (such as customized template, style, attributes) after 11g upgrade? Still be usable?
    4. Customer use PDK to develop many portlets in 10g. Can they use JDeveloper 11g to migrate their old project to 11g automatically?
    Thank you in advance and any comment are welcome.

    1. Whether the 'Instant Portal' feature remain in Oracle Portal 11g? If yes, how to migrate the Instant Portal 10g sites? If no, any workaround?Instant Portal is not available anymore in Oracle Portal 11g. The Instant Portal page groups will be migrated to standard Portal page groups. Maintenance of the Instant Portal can be done with the standard Portal tools. The Instant Portal tools are not available anymore.
    Whether the old 10g Page Group and Pages will be still available after 11g upgrade? Also can customer import the old 10g transportset into Portal 11g?Old 10g Page Groups are migrated to Portal 11g. They will still be available after the upgrade.
    Export/Import through transports sets has always been limited to instances of the same version. It is not supported between versions as documented in the Administration Guide :
    [11.2.1|http://download.oracle.com/docs/cd/E14571_01/portal.1111/e10239/cg_imex.htm#CCJBCCGD] System Requirements
    Before exporting and importing content, ensure that your system meets the minimum system requirements, as described in this section.
    Notes:
    * Export and import functions only within the same release of Oracle Portal and the same patch release, for example, release 10.1.4 to release 10.1.4 or release 11.1.1 to release 11.1.1. You cannot export and import between two different releases, such as release 10.1.2 to release 10.1.4 or release 10.1.4 to release 11.1.1.
    How about the customized Portal 10g objects (such as customized template, style, attributes) after 11g upgrade? Still be usable?Customized objects get migrated as well. Certain types (e.g. PL/SQL item types) need to be checked after upgrade as the behavior of the PL/SQL code may differ between database versions. This is particularly of concern when the 10.1.4.x Portal uses a 10.1 database. A database upgrade to either 10.2, 11.1 or 11.2 is necessary as Portal 11g is not supported with RDBMS 10.1.
    Customer use PDK to develop many portlets in 10g. Can they use JDeveloper 11g to migrate their old project to 11g automatically?Never done this, but the Portal framework is able to consume JPDK providers which are running in older versions of the toolkit. If the providers are running in standalone OC4J containers, you would be able to upgrade the framework and keep the providers in their OC4J containers. This will allow you to focus on the framework first and worry about your providers later.
    Thanks,
    EJ

  • Urgent help required about nokia N8

    I was updating my phone software whine installation suddenly power off and my phone turn off... Now when I switch on it nothing papers on screen please help what should I do....? 

    @MHassan125
    A black screen usually indicates device still in flash mode and a visit to Nokia Care facility for device software to be re-installed is required.
    Happy to have helped forum with a Support Ratio = 42.5

  • Need help: question about itunes update problem

    I started up iTunes yesterday and a window popped up saying there was a new version of iTunes to update, so I did it, and now I can't save equalizer presets! The feature doesn't work at all anymore, and it used to work great. It just goes back to Manual every time, and just won't save anything you put in. This really frustrates me, as it was one of my fave things about iTunes. Can anybody tell me what happened? Can I fix it or go back to my old version without losing my library?
    Cheers

    How do I make sure I don't lose my library? if i uninstall and then re-install an older version (which I have on disc), how do I make sure my library comes with me?

  • A question about List

    Can anyone please explain what the square symbol after an added file name in a List object is.

    It is the run-time type signature.
    *see full list in the 'Type Signatures' section in this link: http://java.sun.com/j2se/1.5.0/docs/guide/jni/spec/types.html
    Z boolean
    B byte
    C char
    S short
    I int
    J long
    F float
    D double
    L fully-qualified-class ; fully-qualified-class
    [ type  type[]
    ( arg-types ) ret-type method type
    For example, the Java method: long f (int n, String s, int[] arr); has the following type signature: (ILjava/lang/String;[I)J                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Urgent: A question about jadtool

    I read some document and got the idea that
    JDK tool jarsigner can be used for jar signing and signature verification,
    but WTK tool jadtool can only be used for MIDlet signing but cann't be used for signature verification.
    If I want a promp way to verify a signed MIDlet, what could I use?
    Thank you for help.

    That's because you've put the bean in the request scope : request object dies when servlet or JSP sends info back to the browser and closes the stream (ie : when page is shown in client browser).
    An easy solution is to put the bean in session scope.

  • Help, question about "select ... for update nowait"

    There is a proc code. In the beginning of the code, I used a SQL "select ... for update nowait" in order to prevent from another proc executing at the same time. When the case happens, "-54, ORA-00054: resource busy and acquire with NOWAIT specified" will be printed in the screen.
    But there is a question: I need to print sth to indicate "another proc is running". I used "if (sqlca.sqlcode == -54)" as precondition, such as:
    if (sqlca.sqlcode == -54) {
    printf("There is another proc running.\n");
    However, this line will not be printed. I doubt that the code quits directly when using "select ... for update nowait" so as not to set value (-54) to sqlca.sqlcode.
    So, could you suggest whether there is another way that I can use to print "There is another proc running" when another proc is running?
    Thx a lot for your kindly reply.

    Yes, that link. Scroll down a bit and you will see:
    The calling application gets a PL/SQL exception, which it can process using the error-reporting functions SQLCODE and SQLERRM in an OTHERS handler. Also, it can use the pragma EXCEPTION_INIT to map specific error numbers returned by raise_application_error to exceptions of its own, as the following Pro*C example shows:
    EXEC SQL EXECUTE
    /* Execute embedded PL/SQL block using host
    variables v_emp_id and v_amount, which were
    assigned values in the host environment. */
    DECLARE
    null_salary EXCEPTION;
    /* Map error number returned by raise_application_error
    to user-defined exception. */
    PRAGMA EXCEPTION_INIT(null_salary, -20101);
    BEGIN
    raise_salary(:v_emp_id, :v_amount);
    EXCEPTION
    WHEN null_salary THEN
    INSERT INTO emp_audit VALUES (:v_emp_id, ...);
    END;
    END-EXEC;
    This technique allows the calling application to handle error conditions in specific exception handlers.

  • [Urgent] Some questions about OID/OSSO 10g - 11g upgrade

    Dear all,
    We are under doing upgrading assessment of OID/OSSO 10g to 11g for a customer. After reviewed the 'upgrading guide', we still have some questions as below:
    1.     Whether the ‘10g DIP profiles’ will be still available after the OID 11g upgrade? Currently there are some sync of AD<->OID and DB->OID.
    2.     Whether the ‘WNA’ function will still work after the upgrade?
    3.     Is there a big change of OID API from 10g to 11g? If so, I think a big effort maybe on application modification.
    4.     I found that there is a OAM Basic version for OSSO 10g upgrade. So if this OAM Basic will migrate the OSSO configuration (like external application) automatically, or it must be re-configed after the upgrade?
    5.     Currently customer config OID 10g as BPEL/ESB’s identity store. So does BPEL/ESB 10g is certificated with OID 11g also? I didn’t find the certification so far.
    Thank you in advance and any comment are welcome.

    Dear all,
    We are under doing upgrading assessment of OID/OSSO 10g to 11g for a customer. After reviewed the 'upgrading guide', we still have some questions as below:
    1.     Whether the ‘10g DIP profiles’ will be still available after the OID 11g upgrade? Currently there are some sync of AD<->OID and DB->OID.
    2.     Whether the ‘WNA’ function will still work after the upgrade?
    3.     Is there a big change of OID API from 10g to 11g? If so, I think a big effort maybe on application modification.
    4.     I found that there is a OAM Basic version for OSSO 10g upgrade. So if this OAM Basic will migrate the OSSO configuration (like external application) automatically, or it must be re-configed after the upgrade?
    5.     Currently customer config OID 10g as BPEL/ESB’s identity store. So does BPEL/ESB 10g is certificated with OID 11g also? I didn’t find the certification so far.
    Thank you in advance and any comment are welcome.

  • Help  question about calculating sum????

    what do i need to fix to make it so the digits add together to give a sum i know its in the loop but i cant figure it out can someone giv me a hint
    thanks
    import java.util.Scanner;
    import javax.swing.JOptionPane;
    public class ch10q8
        public static void main(String[] args)
            String input;
            char[] array;
            int digits = 0;
            input = JOptionPane.showInputDialog("Enter numbers seperated by commas");
            array = input.toCharArray();
            for (int i =0; i < array.length; i++)
                if (Character.isDigit(array))
    digits++;
    JOptionPane.showMessageDialog(null, "The digits total" + digits);
    System.exit(0);

    Hey Mr. javakinglow, you never responded to replies in your last three threads:
    [thread 1|http://forums.sun.com/thread.jspa?threadID=5376244&messageID=10656940#10656940]
    [thread 2|http://forums.sun.com/thread.jspa?threadID=5376219&messageID=10656857#10656857]
    [thread 3|http://forums.sun.com/thread.jspa?threadID=5373645&messageID=10642792#10642792]
    This kind of implies that you possibly didn't even read the replies and that you'll likely not read or respond to replies to this thread. Are you sure that this is the message that you want to send?
    Best of luck.

  • I have an urgent question about my indesign. I had problems with the creative cloude app and then uninstalled it and then installed it again. Now it is not opening and I cannot download it again either. Pls give me help and advice if there is anything I c

    I have an urgent question about my indesign. I had problems with the creative cloude app and then uninstalled it and then installed it again. Now it is not opening and I cannot download it again either. Pls give me help and advice if there is anything I can do to repair it

    Please authorize ADE 3 with same credentials that you used with older version of ADE

  • Please help me about question security because in my apple id no have for restart or chenge my answer

    please help me about answer security question in my apple id because im forgot for my answer, in my apple id no have for change answer, tell me for this please because i love my iphone.
    <Email Edited by Host>

    You need to ask Apple to reset your security questions; this can be done by clicking here and picking a method, or if your country isn't listed, filling out and submitting this form.
    They wouldn't be security questions if they could be bypassed without Apple verifying your identity.
    (110899)

  • Need urgent help in listing out checklist from DBA prespective for BI Implementation Project

    Hello Guys,
    We are in Designing phase Data Modeling of PDW/APS Implementation Project.
    I need urgent help in making a checklist from a DBA perspective.
    Like what are things ill be needing at a time of implementation/Deployment.
    Your expert comments and help will be highly appreciated.
    Thank you,
    Anish.S
    Asandeen

    You can get good summary of checklist from this article about
    DBA checklist for data warehousing.
    Which highlights on below pointers:
    New system or old. (I.e. Up-gradation vs starting from scratch)
    Complexity of SQL Server architecture 
    SQL Server storage
    Determining SQL Server processing power
    SQL Server installation consideration 
    SQL Server configuration parameter
    SQL Server security
    SQL Server Database property
    SQL Server jobs and automation
    Protecting SQL Server data
    SQL Server health monitoring and check ups
    SQL Server ownership and control 
    based on my real time experience, I will suggest you to keep an eye on 
    Load performance (It will be useful when your database(Warehouse) will have huge amount of data)
    System availability (Check for Windows update and up time configuration) 
    Deployment methodology should be planned in advance. Development of packages and respective objects should be done systematically.
    Source control mechanism 
    Disk space and memory usage
    You might or might not have full rights on production environment, so be prepared to analyze production environment via Select statements [I guess you got my point]
    Proper implementation of Landing , Staging and Mart tables.
    Column size (this can drastically decrease your database size)
    Usage of indexes (Index are good, but at what cost?)
    I hope this will assist you in building your check list.

  • TS2446 I forgot the security question about what was my first car and what is my favorite car! What is the solution to change that? please help me, thank you in advance Leo

    I forgot the security question about what was my first car and what is my favorite car! What is the solution to change that? please help me, thank you in advance Leo

    If you have a rescue email address set up on your account then you can try going to https://appleid.apple.com/ and click 'Manage your Apple ID' on the right-hand side of that page and log into your account. Then click on 'Password and Security' on the left-hand side of that page and on the right-hand side you might see an option to send security question reset info to your rescue email address.
    If you don't have a rescue email address set up then go to Express Lane  and select 'iTunes' from the list of 'products' in the middle of the screen.
    Then select 'iTunes Store', and on the next screen select 'Account Management'
    Next choose 'iTunes Store Account Questions' or 'iTunes Store account security' (it appears to vary by country) and fill in that you'd like your security questions/answers reset.
    You should get an email reply within about 24 hours (and check your Spam folder as well as your Inbox)

Maybe you are looking for

  • Help: iSync Error When iSync to Blackberry

    I have owned my BB for over a year. And I have never had this problem until this morning. It seems to happen when iSync starts to merge with my iCal. Any suggestions would be appreciated. Blow are the error messages I keep receiving - thank you. Davi

  • Quicktime will not load Apple iPhone OS4 Keynote from Safari

    (iMac) I have been trying to watch the OS4 keynote off the apple website for a few days now. When i press watch it loads up quicktime and all i get is a white background with a quicktime logo with a loading dotted bar at the bottom. It does this with

  • Using multiple locales in Flash Builder 4.7

    Is there a known issue in FB4.7 adding multiple locales in the compiler arguments? I'm trying: -locale fr_FR,en_US ...but it looks like FB is trying to find a single locale with the name 'fr_FR,en_US' rather than the pair: unable to open '/Applicatio

  • Combining mulitple image files into a PDF results in different pages sizes

    Hi I prepared 150 images in Photoshop using a script. All the images are the same pixels dimensions, same resolution and same file type. When I combine them into a PDF using Acrobat XI, some of the pages are very small. I cannot see the logic as to w

  • There's Something Very Wrong With My Macbook... Please Give Me Some Advice

    I bought a new black macbook about 7 months ago: Here are the specs: Model Name: MacBook Model Identifier: MacBook2,1 Processor Name: Intel Core 2 Duo Processor Speed: 2.16 GHz Number Of Processors: 1 Total Number Of Cores: 2 L2 Cache (per processor)