Looping over a TreeMap with for|foreach

I am a student programmer and am impressed how the APIs for the different collections are very similar if not completely identical.
I used treemap.keySet() to loop over TreeMap<String, MyVeryOwnClass> successfully with a while loop. But it seems impossible to do the same with the newish for-each loop. Or have I missed the point somewhere?
Regards,
Hedley

Okay, I've got the for/each loop working its way through my Applicant TreeMap as follows:
    public String findApprovedApplcnt()
        String applicantKey = "";
        for (Map.Entry<String, Applicant> entry : applicantList.entrySet())
            Applicant applicant = entry.getValue();
            boolean approved = applicant.isApproved();
            if (approved);
                applicantKey = applicant.getApplcntKey();
                // The String key is hashed and stored in an instance variable when object created.
                // It is subsequently retrieved and used when the object is added to the tree map.
                break;
        return applicantKey;
    } // findApprovedApplcnt(..)In the Applicant class is the flag 'private boolean approved = false;' (initially), accessed by the method .isApproved(). What the loop is supposed to do is examine each Applicant object applicant in turn, skip over those where approved = false, and grab the key of the first applicant where approved = true, then break out of the loop and return the key.
Trouble is, it is grabbing the key of the first applicant it encounters regardless of whether approved is either true or false! I have gone nuts over this, stepping through in the debugger, inserting println statements to check the value of approved when it is retrieved, attempting to desk check, etc.
So what is the obvious error to which I am completely blind?
Regards,
Sleepless in Melbourne

Similar Messages

  • Looping over arraycollection with sap data

    Hello,
    I asked a lot of persons but i still have a problem.
    I am trying to make a organizational chart in Adobe Flex with data out of the SAP system.
    When I try to access my data that I have given trough the Flash Islands container it doesn’t work.
    I do:
    [Bindable]
    Public var datasource:Arraycollection;
    Then I want to loop over this datasource with a for loop but it says that the object is null.
    for (i = o; i < datasource.length; i++)
    When I use datasource as dataprovider for a datagrid in Flex, that works perfect.
    Please answer fast because I need it for school.
    greetings

    Hello,
    I asked a lot of persons but i still have a problem.
    I am trying to make a organizational chart in Adobe Flex with data out of the SAP system.
    When I try to access my data that I have given trough the Flash Islands container it doesn’t work.
    I do:
    [Bindable]
    Public var datasource:Arraycollection;
    Then I want to loop over this datasource with a for loop but it says that the object is null.
    for (i = o; i < datasource.length; i++)
    When I use datasource as dataprovider for a datagrid in Flex, that works perfect.
    Please answer fast because I need it for school.
    greetings

  • Loop over hashMap (c:forEach for JSF)

    Hi,
    is there anything like c:forEach for JSF?
    i need to loop over a hashmap.
    i cant use jstl cause ive to use the jsf taglib inside the loop.
    thanks,
    seb

    The h:dataTable can iterate over maps. Tomahawk's t:dataList is an option if you rather want lists instead of tables.
    Accessing a map in EL isn't that hard:"#{myBean.map.key}"resolves tomyBean.getMap().get("key");

  • [Solved] Foreach loop that loops over all files in a folder does not consider first file found

    Hello,
    I have a foreach loop in SSIS (as part of Visual Studio 10 and with SQL Server 2012).
    It loops over all files in a folder (ForEach File Enumerator).
    I set the folder: OK
    Traverse Sub folders: OK
    I have set up a Variable in Variable Mappings called FileName so it shows User::FileName: OK
    Index of variable is 0: OK
    It almost works ok. Except that the first file it finds is never considered.
    I set a breakpoint then and the first file it finds, is shown in black in the watch variable window. All subsequent files found are shown in red font. When I change the names of the files so another file is the first file found then it skips the other one
    which now is the first file.
    What is going on here? Why does SSIS skip the first file it finds in a foreach file loop?
    Any suggestions highly appreciated.
    Thank you
    Andi
    Andreas

    "red font - interesting, any example to show us (image)
    It would be interesting to share with us whether you use any file masks or expressions.
    Arthur
    MyBlog
    Twitter
    It appears a variable value turns red when it changes between breakpoints. It started black for the first value (the first file, obtained BEFORE the execution reached the breakpoint), and then turned red. I was able to reproduce this behavior on a test environment.
    However, it did not skip any files.
    OP, please set up the test shown in the image below. Create a breakpoint in the sequence container for the "OnPreExecute" event.

  • How use c:forEach to loop over a String[][]

    Hello,
    Is there anyone that can tell me how to use the c:forEach tag to loop over a double String[][]? I can find examples for resultsets etc....but whatever I try with my String[][], I never can get the results on the screen.
    Thanx,
    debeumers

    You need to set up a double c:forEach loop.
    ie
    <%
    // initialisation of string[][]
    String[][] sValues = new String[5][5];
    for (int i=0; i<sValues.length; i++){
      for (int j=0; j<sValues.length; j++){
         sValues[i][j] = "" + (i + j);
    pageContext.setAttribute("arrayValues", sValues);
    %>
    // And now to test print out the values
    <c:forEach var="row" items="${arrayValues}">
    <c:forEach var="col" items="${row}">
    <c:out value="${col}"/>
    </c:forEach>
    <br>
    </c:forEach>
    Hope this helps
    Cheers, evnafets

  • Problem with Message-Mapping: Loop over Elements possible?

    Hi all,
    I want do create a Message-Mapping for an IDoc-to-File Scenario. In the Source Structure there are some Elements which can appear more than once (1..unbounded). I need a mechanism which loops over these elements and search for specified values. From the Element which contains an element with this specified value the mapping should write a value in the target structure.
    Here a simple example (source structure) for better understanding:
    <root>
       <invoice>
          <number> 10 </number>
          <sum> 200.00 </sum>
       </invoice>
       <invoice>
          <number> 20 </number>
          <sum> 150.00 </sum>
       </invoice>
       <invoice>
          <number> 30 </number>
          <sum> 120.00 </sum>
       </invoice>
    </root>
    Now the duty of the Mapping should be to search in the elements <invoice> for the number 30. And then the sum of the invoice with the number 30 should be written in a field of the target structure.
    I tried it out with a constant togehter with an equalsS-function and an ifWithoutElse-function, but it is working only then, if the invoice with the number 30 has the first position in the root context.
    Can anybody help me? Thanks
    With kind regards
    Christopher

    Hi,
    Write a UDF to sum the required values and map to target node.
    See while writing the UDF select the type as queue.
    number -- removecontext-UDF targetnode
    sum----removecontext--/
    number abd sum or the two inputs
    in UDF
    int nsum = 0;
    for(int i;i < number.length;i++){
      if number(i).equals("30") then
         nsum = nsum + valueOf(sum(i));
    result.addValue(nsum); // convert the nsum into string
    Regsrds
    Chilla

  • I have been offered cc 2014 for 29.99 and its says contact the support team to see if I qualify - trying to get to the support team option by telephone just seems to send me in a loop - getting pretty disgusted with all the rigmarole just to get a somethi

    I have been offered cc 2014 for 29.99 and its says contact the support team to see if I qualify - trying to get to the support team option by telephone just seems to send me in a loop - getting pretty disgusted with all the rigmarole just to get a something

    This is an open forum, not Adobe support... you need Adobe staff to help
    Adobe contact information - http://helpx.adobe.com/contact.html
    -Select your product and what you need help with
    -Click on the blue box "Still need help? Contact us"
    -or by telephone http://helpx.adobe.com/x-productkb/global/phone-support-orders.html

  • I have taken over 9999 pictures with my phone and it is now creating duplicate names for the pictures starting back at 0001 making it difficult to manually upload my photos like i always have. How do i fix this?

    I have taken over 9999 pictures with my phone and it is now creating duplicate names for the pictures starting back at 0001 making it difficult to manually upload my photos like i always have. How do i fix this?
    (I tried to just write this as a reply to someone who had already asked the question whos problem was magically solved after posting the question and the site was not allowing me to post to it so here I am)

    Additionally, when I try to sort the photos by date to easily extract the newest photos which I have not yet uploaded, it is unable to put them in correct order regardless of the fact that the date is correct. Only the videos end up in chronological order for some reason while the photos stay in order by name.

  • Help on changing array elements with For loop

    Hi,
    I'm wondering if anyone can help me with this problem.  I'd like to be able to modify elements of an array with For loop.  In the attached VI, my goal is to have an array of [0 1 2 3 4 5], but instead what I've got is [2 2 2 2 4 5].  I initialized the array with a value of 2 to help me identify which elements are changing.  Can anyone help me pointing where my mistake is?  Thanks.
    Peter
    Attachments:
    Array test.vi ‏19 KB

    It's a classic issue for LV newbies. In this case you HAVE to use a
    shift register otherwise the modifications of previous cicles are lost.
    It's all easier than it's seems, see attached vi.
    bye,
    manga
    Attachments:
    Array test 2.vi ‏19 KB

  • My iphone is getting hot and draining the battery, it just started yesterday, I've had it for over a year with no problems

    My iphone is getting hot and draining the battery. This started yesterday, I've had the phone for over a year with no problems,

    Delete and re-download the Dropbox app. You will have to sign in again and adjust app settings.

  • After ios 8.02 update iCloud Drive is stuck in a loop that reads "upgrading" with a spinning wheel spokes for the last 48 hours.

    After ios 8.02 update iCloud Drive is stuck in a loop that reads "upgrading" with a spinning wheel spokes for the last 48 hours.

    There's a solution posted here that may work for you: iCloud Drive won't stop upgrading.

  • Since upgrading iPhone 4S to new OS it has not worked. Now over 10 days with no phone, talked to Apple Care in Colorado and Australia over 10 hrs on phone 7 consultants. All that has to happen is for someone at Apple Care to reset a password? Help

    Since upgrading iPhone 4S to new OS it has not worked. Now over 10 days with no phone, talked to Apple Care in Colorado and Australia over 10 hrs on phone 7 consultants. All that has to happen is for someone at Apple Care to reset a password? Phone and Apple ID don't recognise each other. This is nuts!

    The phone will not recognise Apple if passwords or secret questions

  • How can i loop over treeview selected nodes and then to delete each node if it's a directory or a file ?

    I have this code:
    if (s == "file")
    file = false;
    for (int i = 0; i < treeViewMS1.SelectedNodes.Count; i++)
    DeleteFile(treeViewMS1.SelectedNode.FullPath, file);
    I know it's a file and it is working if it's a single file.
    On the treeView i click on a file right click in the menu i select delete and it's doing the line:
    DeleteFile(treeViewMS1.SelectedNode.FullPath, file);
    And it's working no problems.
    But i want to do that if i selected some files togeather multiple selection then to delete each file.
    So i added the FOR loop but then how do i delete from the SelectedNodes each node ?
    The treeView SelectedNodes dosen't have FullPath like SelectedNode also doing SelectedNodes[i] dosen't have the FullPath property.
    Same as for if i want to delete a single directory or multiple selected directories:
    This is the continue of the code if it"s not a "file" (else) it's null i know it's a directory and doing:
    else
    file = true;
    RemoveDirectoriesRecursive(treeViewMS1.SelectedNode, treeViewMS1.SelectedNode.FullPath);
    Also here i'm using SelectedNode but if i marked multiple directories then i how do i loop over the SelectedNodes and send each SelectedNode to the RemoveDirectoriesRecrusive method ?
    My problem is how to loop over SelectedNode(multiple selection of files/directories) and send each selected file/directory to it's method like i'm doing now ?

    foreach (TreeNode n in treeViewMS1.SelectedNodes)
    // Remove everything associated with TreeNode n here
    I don't think it's any harder than that, is it?
    If you can multi-select both an item and one of its descendents in the tree, then you'll have the situation that you may have deleted the parent folder and all of its children by the time you get around to deleting the descendent.  But that's not such
    a big deal.  A file can get deleted externally to your program too - so you'll just have to deal with it having been deleted already (or externally) when you get around to deleting it yourself.

  • Message-Mapping: nested Loops over Elements

    Hi Experts,
    I have problems with my Message-Mapping in the IR. I have a source and a target structure. In the following I will give you easy examples of these structures:
    <u>source structure:</u>
       <E1EDP01>
          <E1EDP19>
             <QUALF> ... </QUALF>
             <IDTNR> ... </IDTNR>
          </E1EDP19>
          <E1EDP19>
             <QUALF> ... </QUALF>
             <IDTNR> ... </IDTNR>
          </E1EDP19>
       </E1EDP01>
       <E1EDP01>
          <E1EDP19>
             <QUALF> ... </QUALF>
             <IDTNR> ... </IDTNR>
          </E1EDP19>
          <E1EDP19>
             <QUALF> ... </QUALF>
             <IDTNR> ... </IDTNR>
          </E1EDP19>
       </E1EDP01>
    <u>target structure:</u>
    <LineItem>
       <IDTNR></IDTNR>
    </LineItem>
    <LineItem>
       <IDTNR></IDTNR>
    </LineItem>
    That means:
    For every <E1EDP01> in the source structure I create one <LineItem> in the target structure. One E1EDP01-Element can contain more than one E1EDP19-Elements. I have to loop over these E1EDP19-Elements, because I have to locate the Element <QUALF> with a given (fixed) value. The Mapping should put the value from the Element <IDTNR> from the source structure - where the QUALF-Element has this given value - in the IDTNR-Element of the target structure.
    I tried it with a UDF, but only the first <IDTNR> in the target structure got filled.
    Thanks for your help
    Christopher

    Thank you,
    but how I can set the Elements IDTNR and QUALF to the context E1EDP01?
    In the splitByValue-Function do I need "each value"?
    best regards
    Christopher

  • Looping over QoQ Where Clause

    I have two queries. One is a main query that we pull from a form submission. The second is a small query resultset that lists different subgroups in my company and what main group they belong to. I pull several QoQ from the main query. In the main query results, there is a column that holds the subgroup information. I am trying to do a Q0Q where I group the data from the main query into the main groups for analysis. Here is an example...
    Main Query
    record 1 - subgroup 1
    record 2 - subgroup 2
    record 3 - subgroup 3
    Second Query
    Subgroup 1 - Main Group 1
    Subgroup 2 - Main Group 2
    Subgroup 3 - Main Group 1
    So I am trying to loop over a QoQ on the main query where the result set would contain the information only from Main Group 1. So record 2 would be eliminated. I have tried using an IN clause with a cfloop, but I run into syntax trouble with the comma. I also tried looping over the QoQ as a whole and the resulting dump is only the last record.
    If there is anything else you need, let me know.
    Any thoughts?
    Clay
    P.S. Here is a code sampling...
        <cfquery name="rsGroup" datasource="nps">
        SELECT *
        FROM "GROUP"
        WHERE GROUP.PrimaryGroup = '#form.primarygroup#'
        </cfquery>
        rsGroup - <cfdump var="#rsGroup#">
        <cfloop query="rsGroup" startrow="1" endrow="#rsGroup.RecordCount#">
            <cfquery name="rsGroupQoQ" dbtype="query">
            SELECT *
            FROM rsNPS
            WHERE rsNPS.grp = '#rsGroup.group#'
            </cfquery>
        </cfloop>
        rsGroupQoQ - <cfdump var="#rsGroupQoQ#"><cfabort>

    ok...I figured it out. I thought I would post my solution in case anyone else runs into this. Also, if anyone out there has a better way, let me know.
    <!---Dummy array to house 'blank' value for adding of column to main query--->
    <cfset GroupArray = ArrayNew(1)>
    <!---Variable that adds mainGroup column to main query with blank data from dummy array--->
    <cfset addMainGroup = QueryAddColumn(rsNPS,'mainGroup',GroupArray)>
    <!---Loop that sets value on added mainGroup column based off of main query grp column value--->
    <cfloop query="rsNPS" startrow="1" endrow="#rsNPS.RecordCount#">
        <cfif rsNPS.GRP EQ "xxxxx"><cfset rsNPS.mainGroup = "yyyyy"></cfif>
        <cfif rsNPS.GRP EQ "xxxxxxxxxx"><cfset rsNPS.mainGroup = "yyyyyyyyyy"></cfif>
        <cfif ...etc. ...
    </cfloop>

Maybe you are looking for

  • Error trying to create a Power View report against a Multi Dimensional SSAS cube

    Hi all, We have installed the Power View For Multidimensional Models CTP, released last November 27 on our Analysis Server instances.  I am now trying to create a Power View report in SharePoint that is connected to a Multi-Dimensional cube. I have f

  • HELP!  I must go back to iWeb 1.2 from iWeb 2.0.1

    The latest version of iWeb doesn't work for me and I must go back. I know how to uninstall and reinstall my previous iWeb (I guess that means I have to go back to iLife 6.0 totally) but I do not know if there is a way to get my website back to the iW

  • Screen sharing between SnowLeo and Leo?

    I have a G5 with 10.5.8 and the rest of my computers are all Intel based. If I upgrade to SnowLeopard would I be able to use the screen sharing feature with my 10.5.8 G5? Thank you. F

  • 30-pin digital av adapter

    Why on ios7 , when I plug-in 30-pin digital av adapter, and turn on video , no longer shown "tv connected , this video-" on ios5.1.1, everything was working in same programme-

  • Insert Into . . . only if today's date

    Sorry if the is a dumb question.  I have a table with lots of dates.  I want to copy only the current date from staging to production.  The only thing I can think of is that maybe the time is throwing it off...but that should be... The [date] filed l