Element in two lists

Hey,
I got a class for a tabbing page that is stored in an ArrayList A. This list A
contains various pages for a JTabbedPane. Only some of those pages will
also be stored in another ArrayList B. Hence list B will be smaller than A.
When I remove such a tabbing page in list A, I'll check also a certain
boolean if it is contained in list B, too.
How can I get the index now in list B in an elegant way? First I gave all of
those tabbing page classes an index variable for B, that I could check. My
problem was, it seems to be a bit clumsy and I need to update that variable
after each action (add/remove). Now I thought about in case I'd like to
remove a page, to run thru the list B and compare the elements in that list
directly with the one which is to be removed or compare just hashCode's of
these elements with the one to be removed, in case it would work?!
Which solution solves my problem best? - the first using an additional variable, comparing the elements or comparing just the hashCodes with the one element to be removed? TIA

don't know the 'best' way, but if the elements of B are added from A,
this might be all you need to do.
    Object o = listA.get(2);//<--2 is any number
    for(int x = 0,y = listB.size(); x < y; x++)
      if(listB.get(x).equals(o))
        listB.remove(x);
    }

Similar Messages

  • How to Merge the elements of two separate lists into a single one .

    Hi ,
    I am unable to add elemnts of 2 separate Lists suppose list1= { HashmapA, HashMapB}
    List2 = { HashmapC, HashMapD } into the third list List3 whose elements should be
    { HashmapA, HashMapB,HashmapC, HashMapD } .
    I am trying Collections.addAll(List3 ,List2 ,list1)
    but it is giving me a list whose elements are 2 lists( 0 -> list1,1->list2) and not { HashmapA, HashMapB,HashmapC, HashMapD }.
    Can anyone help me out with this !!!!!

    I am unable to add elemnts of 2 separate Lists suppose list1= { HashmapA, HashMapB}
    List2 = { HashmapC, HashMapD } into the third list List3 whose elements should be
    { HashmapA, HashMapB,HashmapC, HashMapD } .
    You can also try
    Set<T> union = new HashSet<T>(list1);
    union.addAll(list2);Assuming you want to get rid of the duplicates. Replace T with the actual type of your elements.

  • Add an element to the list in run time

    There is an item in my form which is a list of values.It is getting populated based on a record group query.
    I want to let the user enter values at run time and add the values to the exiting list in the form and same
    should be added to the record group so that next time i open the form the added value can be seen.
    Is this possible?
    Regards,

    I have written this code on when_button_pressed trigger to populate the record group RGSTD and LOV(Name LOVSTD).
    I have added the element in the list using add_list_element built in. But it is not giving me proper results.
    Record group has two columns STDID and STDNAME.
    DECLARE
    ln_num NUMBER := 0;
    BEGIN
    ln_num := show_alert('ALERT15');
    IF ln_num = 88 THEN
    add_group_row('RGSTD', 1);
    set_group_char_cell('STDID', 1, 'ST00004');
    set_group_char_cell('STDNAME', 1, 'Add To List');   
    add_list_element('LOVSTD', 1, 'Add To List', 'Add To List');  
    ELSE
    NULL;
    END IF;
    END;Edited by: LostWorld on Feb 9, 2009 5:49 AM

  • Merging two lists?

    I need to know if it is possible to merge two lists using coldfusion.  I have one list uploaded to the site then they want the ability to upload a second list with may have additional fields and/or different number of records.  Need to know if this is possible, how to do it if it is, and how the two list will match up.  Thanks in advance for the help.

    Right, well in that case this isn't really anything to do with merging lists per se, hence the confusion I believe. Technically, you'd do this:
    <cfset newData = fileOpen("c:\newlist.csv","read") />
    <!--- Loop through your file, one line at a time --->
    <cfloop condition="NOT fileIsEof(newData)">
      <!--- Create a string of the line, this is a true list --->
      <cfset thisLine = fileReadLine(newData) />
      <!--- Get the elements of the list we want for the query --->
      <cfset thisForename = listGetAt(thisLine,1) />
      <cfset thisSurname = listGetAt(thisLine,2) />
      <!--- Check if this person exists --->
      <cfquery datasource/username/password name="qCheckExists">
        SELECT    id
        FROM      mytable
        WHERE     firstname = <cfqueryparam cfsqltype="cf_sql_varchar" value="#thisForename#" />
        AND       surname = <cfqueryparam cfsqltype="cf_sql_varchar" value="#thisSurname"#" />
      </cfquery>
      <!--- If we found rows, update --->
      <cfif qCheckExists.RECORDCOUNT eq 1 >
        <cfquery datasource/username/password>
            UPDATE   mytable
            SET      forename = <listGetAt,thisLine, FIELD>,
                     surname = <listGetAt,thisLine, FIELD>,
                     address = <listGetAt,thisLine, FIELD>,
                         etc etc etc
            WHERE    id = qCheckExists.id
        </cfquery>
      <cfelseif qCheckExists.RECORDCOUNT >
        <!--- here you found more than one matching row, up to you what to do --->
      <cfelse>
        <!--- here you didn't find a match, so do an insert --->
      </cfif>
    </cfloop>
    <cfset fileClose(newData) />
    That's how you'd do it on a technical level, the Business decisions are yours. What if it's John not Jon? What if it's Jonathan? That's not a programming problem, that's up to you to decide - I'm not sure we can help you there.
    O.

  • Is it possible to rearrange the elements in a List after removing indexes?

    Hello,
    I am hoping someone can help me out w/a question.
    I have a list
    List<String>  Labels = new ArrayList<String> ();and I add 3 elements in the list
    labels.add("one"); //index 0
    labels.add("two"); //index 1
    labels.add("three");  //index 2Later on in the program I remove 2 indexes,
    labels.remove(0);
    labels.remove(2);When i try to iterate through labels it throws
    Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: Index: 1, Size: 1I perfectly understand the error. My question is this: after removing the indexes, how can i rearrange the list so that the one element that is left (currently at index 1) is set at index 0 so that it doesn't throw an exception ? is this doable ?
    Thanks very much for your help!!

    va97 wrote:
    Hello,
    I am hoping someone can help me out w/a question.
    I have a list
    List<String>  Labels = new ArrayList<String> ();and I add 3 elements in the list
    labels.add("one"); //index 0
    labels.add("two"); //index 1
    labels.add("three");  //index 2Later on in the program I remove 2 indexes,
    labels.remove(0);
    labels.remove(2);
    This doesn't work!
    Before those call the List looks like this:
    [one, two, three].
    After you call remove(0), it will look like this:
    [two, three]
    Now, when you try to call remove(2), it will throw an IndexOutOfBoundsException, as there is nothing at index 2 anymore.
    I perfectly understand the error. My question is this: after removing the indexes, how can i rearrange the list so that the one element that is left (currently at index 1) is set at index 0 so that it doesn't throw an exception ? is this doable ?I'm afraid you don't understand the error message correctly, since then your question would be different.
    The error message says "you tried to access something at index 1, but this list only is of size 1". This means that the only valid index at that moment is 0.

  • The best way to check the differences between two lists? Or substracting

    Hi,
    I am Googling on this and find many different answers and I am not sure what the best approach is. I have two lists:
    List A: with 10000 entries (String with length 6 all of them)
    List B: with 10002 entries (String with length 6 all of them)
    List A and B are almost identical but with 2 differences. I want to find these two differences or in other words generating a third list, List C with these 2 differences.
    What is the best way to approach? To us Array, ArrayList, Vectors, Hashmap, Hashtable...
    Thank you for any hunches

    Maria1990 wrote:
    I think I found the easiest approach...
    listA = [a, b, c];
    listB = [a, b];
    listC = listA.removeAll(listB);
    ...but if it is the best approach with performance in mind.. I have no idea...It really depends on what sort of comparison you want. Lists allow duplicate elements, Sets do not; so a comparison of Sets based on the contents of your Lists would only return distinct element differences.
    My suggestion: sort both lists and do a "staircase" comparison. That is (assuming they're both in ascending order):
    1. Read through both until you find a mismatch.
    2. Read through the one containing the "lesser" element, until you find a match, or until it's exhausted.
    3. If you find a match, go back to 1.
    4. If you exhaust one list, then any remaining elements in the other are also "mismatches".
    HIH
    Winston
    PS: With this approach, you can also flag your mismatches as "A not in B" or "B not in A".
    Edited by: YoungWinston on Jul 27, 2010 4:24 AM

  • Sort numbers from two lists

    Hello,
    I have two ordered lists LIST1 and LIST2 which elements are composed
    of a field named "value" (an integer number) and a field named "prox"
    that points on the following element ("nil" when there aren't new
    elements).
    The elements are disposes in each list in crescent order of value.
    What's the optimal Java algorithm to print in crescent order the
    combination of the elements of both lists?
    For example, if the first list is formed by values 8, 12, 13, 28, and
    the second by values 10, 11, 35, it must print the list 8, 10, 11, 12,
    13, 28, 35.
    Thanks in advance to all
    Dario

    Hello,
    I have two ordered lists LIST1 and LIST2 which
    elements are composed
    of a field named "value" (an integer number) and a
    field named "prox"
    that points on the following element ("nil" when
    there aren't new
    elements).
    The elements are disposes in each list in crescent
    order of value.
    What's the optimal Java algorithm to print *in
    crescent order* the
    combination of the elements of both lists?
    For example, if the first list is formed by values 8,
    12, 13, 28, and
    the second by values 10, 11, 35, it must print the
    list 8, 10, 11, 12,
    13, 28, 35.
    Thanks in advance to all
    DarioPlease present your algorithm in the form of pseudocode and
    tell us where you have problem with Java.
    this will pinpoint your problem and hence you will get faster response.
    thanks

  • How to add two list in one frame using REUSE_ALV_LIST_DISPLAY

    Hi,
    I want to display two list in single output by calling FM 'REUSE_ALV_LIST_DISPLAY' twice.
    I saw one topic posted by Arunava Das as 'ALV Problem' but didn't get the steps to do that.
    Here is his way of doing that "What I have done is gone for the append ALV approach wher I have added the END_OF_LIST Event for the Fisrt reprt and in the Corresponding FORM Routine I have added another made another cALL to the REUSE_ALV_LIST DISPLAY FM with the other table."
    I would be grateful if someone can help me out.

    Hi Ashish,
    The way you have tried i.e. calling the second list in the END_OF_LIST event of first list and like wise that is the correct way of doing it.
    Using this way you can display multiple lists. In the event END_OF_LIST by using a global variable G_COUNTER. the value of which you increment for each list and based on that counter you call different lists in the END_OF_LIST event.
    case G_COUNTER.
      when 1. perform call_first_list.
      when 2. perform call_second_list.
      when 3. perform call_third_list.
    endcase.
    Hope this answers your query
    regards,
    Satyadev Dutta

  • How to join two lists and display the results in datasheet view.?

    hello,
    i have two lists that i would like to join, i know a method that has been described  in the link below
    http://www.codeproject.com/Articles/194252/How-to-Link-Two-Lists-and-Create-a-Combined-Ciew-i
    however, here the data view is only limited to 30 rows and my resultant list is huge. I would like to know if there is a possibility to view the resultant list in a data sheet view ?

    I don't believe you can use the OOTB Datasheet view when joining lists. However, you should be able to increase your limit from 30 items to as many as you need (that doesn't trip the threshold set in Central Admin).
    Dimitri Ayrapetov (MCSE: SharePoint)

  • Join two list with condition using caml query in SharePoint 2013 with client object model

    Hi,
    Want to join two list to get all fields from both list.
    Am new to sharepoint and sharepoint 2013. Am working in sharepoint 2013 online apps. Am using context.executeQueryasync to load list and get items from list. Am able to get items from single list with caml query, but not able to get both list field values
    with joins.  I did lot of surfing..but not..
    Below is my code..
    ListName1 : "AssignedTasks"
    ListName2 : "Tasks"
     var assignedQueryTest = "<View><Joins><Join Type='INNER' ListAlias='Tasks'><Eq><FieldRef Name='TaskId' RefType='Id'/><FieldRef List='Tasks' Name='ID' /></Eq></Join></Joins>"
                    + "<ViewFields><FieldRef Name='TitleValue' /><FieldRef Name='ActionItemsValue' /></ViewFields>"
                    + "<ProjectedFields>"
                    + "<Field Name='TitleValue' Type='Lookup' List='Tasks' ShowField='Title' /><Field Name='ActionItemsValue' Type='Lookup' List='Tasks' ShowField='ActionItems' />"
                    + "</ProjectedFields>"
                    + "</View>";
                   var web = context.get_web();
                    var list = web.get_lists().getByTitle("AssingedTasks");
                    var myQuery = new SP.CamlQuery();
                    myQuery.set_viewXml(assignedQueryTest);
                    var myItems = list.getItems(myQuery, "Include(TitleValue,ActionItemsValue)");
                    context.load(myItems);
                    context.executeQueryAsync(function () { if(myItems.get_count()>0){....}
    }, errorCallback);
    Here am able to get "AssignedTasks" list field values but not able to get "Tasks" list field values. 
    Can you please help me to resolve the issue. Or new idea for join. I have add the condition also in the query.
    If anybody have good sample, please provide.
    Thanks,
    Pariventhan
    Pariventhan.S

    Hi Pariventhan,
    I don't know about join but I have a workaround of this problem.
    Declare one variable (itemcollection) globally. Load all the items "AssignedTasks" using context.load.
    In the success method call another CAML query using <IN> tag of the ID of the items from the second list (Assuming you have look-up column of the ID of the first list to the second list).
    If this is not clear to you then please let me know. If possible then I can provide code sample.
    Thanks,
    Aniruddha

  • Get data from two list simultaneously using REST

    Is it possible to query two list in the same time?
    url: http://sites.com/url/_api/web/lists/GetByTitle(‘List1')
    url: http://sites.com/url/_api/web/lists/GetByTitle(‘List1' and 'List2')
    Thanks in advance

    Hi ,
    By default SharePoint doesn't provide this kind of rest service or server object model api to retrieve the specified multiple lists once, it could only get all lists or one specified list one time.
    you may query twice to get two lists as a workaround.
    http://msdn.microsoft.com/en-us/library/office/fp142380(v=office.15).aspx
    http://msdn.microsoft.com/en-us/library/jj246453.aspx
    Thanks
    Daniel Yang
    TechNet Community Support

  • Invalid element 'welcome-file-list' in content of 'web-app',

    HI, folks.
    I recently used struts to develop a simple web applicaiton, and whenever I tried to use tag libs
    such as /WEB-INF/struts-html.tld
    /WEB-INF/struts-html.tld and
    tried to compile it, it gives out compile error such as:
    Error(52,21): Invalid element 'welcome-file-list' in content of 'web-app', expected elements '[taglib, resource-env-ref, resource-ref, security-constraint, login-config, security-role, env-entry, ejb-ref, ejb-local-ref]'.
    if I remove the above tag libs, the jsp file compiles
    without any problem.
    Are you guys familiar with these problems?
    please let me know if I'm doing anything foolish.
    Thanks!

    Unless some other elements tag are not close correctly this error does not make sense. Can you cut and paste your web.xml?
    It should look something like:
    <?xml version = '1.0' encoding = 'windows-1252'?>
    <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
    <web-app>
    <welcome-file-list>
      <welcome-file>/untitled1.jsp</welcome-file>
    </welcome-file-list>
    <taglib>
      <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
      <taglib-location>/WEB-INF/struts-html.tld</taglib-location>
    </taglib>
    </web-app>Charles.

  • How to merge alphabetically two lists through a rational solution?

    Have two lists of captions it two languages and need to merge alphabetically, but this solution is very poor.
    (list x)
    Palacio Imperial, Barcelona, 2012
    Cementerio, 2009
    (list y)
    Imperial Palace
    Cemetery
    to obtain:
    Palacio Imperial, Barcelona, 2012
    Imperial Palace
    Cementerio, 2009
    Cemetery
    One method very naive:
    · number the lists
    · convert numbering to text
    · in list y add a constant to sort in order:
    1. Palacio Imperial, Barcelona, 2012
    2. Cementerio, 2009
    1a. Imperial Palace
    2a. Cemetery
    and sort:
    1. Palacio Imperial, Barcelona, 2012
    1a. Imperial Palace
    2. Cementerio, 2009
    2a. Cemetery
    delete the code:
    Palacio Imperial, Barcelona, 2012
    Imperial Palace
    Cementerio, 2009
    Cemetery
    (italics are not required)
    Thanks.

    Camilo,
    Another more original way with QuicKeys! [I love this little soft for a long time!] Only 1 click!
    For it, you need to use a different paragraph style for each list [eg. List1_Style and List2_Style].
    Eg, our list:
    A1
    A2
    A3
    A4
    B1
    B2
    B3
    B4
    Search: (?<=\r)(.+\r)+
    Search format: List1_Style
    Search-Research Windows must be open into ID.
    Shorcut in QuicKeys:
    1rst research
    1/ Click on the button: Search (actived - in blue)
    A2
    A3
    A4
    is selected.
    2/ Cut it (shortcut: Apple+X)
    3/ Down arrow (of the keyboard)
    4/ Copy it
    We obtain:
    A1
    B1
    A2
    A3
    A4
    B2
    B3
    B4
    2nd research
    1/ Click on the button: Search (actived - in blue)
    A3
    A4
    is selected.
    2/ Cut it (shortcut: Apple+X)
    3/ Down arrow (of the keyboard)
    4/ Copy it
    We obtain:
    A1
    B1
    A2
    B2
    A3
    A4
    B3
    B4
    3rd research
    1/ Click on the button: Search (actived - in blue)
    A4
    is selected.
    2/ Cut it (shortcut: Apple+X)
    3/ Down arrow (of the keyboard)
    4/ Copy it
    We obtain:
    A1
    B1
    A2
    B2
    A3
    B3
    A4
    B4
    The research stops automatically.
    The last work (after this test) is to create a loop in QuicKeys to run the steps 1/-2/-3/-4/ as many times as necessary until the end of the process. 

  • Drag and Drop between two list boxes

    Hi all
    I am working over Drag and Drop .. i have to implement Drag and Drop between two list boxes .. both list box exist in same page ..each list box have number of rows.. please give me some idea ... as i am new for JSP and Servlet...
    Thanks in advance
    Regards
    Vaibhav

    Hi all
    I am working over Drag and Drop .. i have to
    implement Drag and Drop between two list boxes ..
    both list box exist in same page ..each list box have
    number of rows.. please give me some idea ... as i am
    new for JSP and Servlet...
    Something close to what you are looking for is Select Mover in Coldtags suite:
    http://www.servletsuite.com/jsp.htm

  • Java 1.5 - Each Element of a List Cannot Be An Array?

    I plan to create a List and each element of this List is a String Array.
    First, I declared a List:
         private static List<String> recursiveTextArray = new ArrayList<String>();And I want to build this List by adding one Array at a time:
    recursiveTextArray.add( title );where
    private String[] title;
    title = new Array(3);I got syntax error saying: "The method add(String) in the type List<String> is not applicable for the arguments (String[]).
    I cannot figure out what the compiler is complaining about. How do I fix the problem? Thanks in advance.

    I think that I have some idea about what is going on. Because Array is an object, I should:
    private static List<Object> recursiveTextArray = new ArrayList<Object>();But the Java statement shown right above has a syntax error: "Syntax error on token ";", , expected"
    I have no clue why there is such a syntax error.

Maybe you are looking for