Determine whether an array contains elements of another array

I have an array whose length is not know (TABLE 1)
I have another array whose length is known (TABLE 2)

I have to see if the table 1 contains elements of table 2 and then form another array that contains elements that are not present in the table Array1.
The values that I face is int values. Also I don't know if I should use tables or any other collection.
I tried to go an and compare other but does not know this exceptionas of arrayIndexoutOfBound gives the length of table 1.
Please suggest how to proceed.

Thank you

>
I want to do another painting where I can put the elements that are in array2, but not in the table array1. How to make
>
There are several ways to do so. Where is the best depends on how many items it can be in each table, if the elements, or both, the tables are already in a sorted order, and if these are real berries or instances of a Collection class.

If you want to just brute force, then we forget about loops nested and just do the simple way. Here is pseudocode, which should be enough for you to write correct code. This method is very effective for all but very little evidence of the table

boolen existsInArray1;
ArrayList array3 = new ArrayList;
-for each element (index value) in array2 loop
     -if notExistsInArray1 (array2[index]) then
            array3.add(array2[index]);
     -end if
-end loop

-new method returns true if parameter exists in array1
public boolen notExistsInArray1 (int myInt) {
    - for each element (index value) in array1 loop
           if array1[index] = myInt return true;
    -end loop
    return false;
}

For a larger number of items you could order to each of the tables in the order, then through table array1 array2 looking for the item. You would keep track of each index value of paintings. If the first element of the array array2 is smaller than the first element of the array array1 it cannot therefore in the table because the list is sorted. So you increment the index of table 1 and test again.

This method is similar to the way in which two sorted files are merged or mapped.

Another way is to create a GAME (does not allow duplicates) for the elements of the array array1 and then use the 'contains' to check each element of the array array2 to see if it belongs to the whole.

CollectionUtils Apache Commons Library also has a method "disjunction".
http://Commons.Apache.org/collections/apidocs/org/Apache/Commons/Collections/CollectionUtils.html

disjunction
public static java.util.Collection disjunction(java.util.Collection a,
                                               java.util.Collection b)Returns a Collection containing the exclusive disjunction (symmetric difference) of the given Collections.
The cardinality of each element e in the returned Collection will be equal to max(cardinality(e,a),cardinality(e,b)) - min(cardinality(e,a),cardinality(e,b)). 

Tags: Java

Similar Questions

  • How to check if a list contains elements of another list

    Hi all

    I'm just checking if a text list contains items form another list and do something. I tried:

    Tlist contains phrases of the text (for example, test1, test2, test3)

    phrases = ["test1", "test2"]
    n = phrases.count)

    tList.getPos (phrases.item [n])
    Alert ("should not be included in the list")

    But it does not all ideas, why?

    There might be a quicker way, but I think you need to loop through at least one of your lists. Maybe something like this:

  • Windows could not determine if this computer contains a valid system volume?

    OK, so I have a laptop VGN-N220E model of Vaio I'm trying to re - install Vista x 32 on. I uninstalled windows and my disks formatted. Completely clean slate. Now I don't have a working disk drive so I will try to re - install from flash drive. I used the Windows 7 ISO tool to put it on my USB on another computer and it worked perfectly. I started to my USB key and the program started installation, but when I go to select my disk 0 Partition 1, I click Next and instantly get "Windows has no determine if this computer contains a valid system volume." I looked everywhere before asking here, and help would be greatly appreciated. I am trying to settle this issue quickly, if possible.

    You choose the USB partition?

    http://answers.Microsoft.com/en-us/Windows/Forum/windows_vista-windows_install/could-not-determine-if-this-computer-contains-a/31e68d8c-44ab-42a8-9b68-1b6cff5fc5dc

    http://support.Microsoft.com/kb/938984

    -This-computer-contains-a-valid-system-volume-error/ http://nctritech.wordpress.com/2009/07/20/Fix-the-Windows-could-not-Determine-if

    http://www.acroment.com/2008/11/Windows-could-not-determine-if-this-computer-contains-a-valid-system-volume/

  • EventID: 1206 Event Source: Active Directory Web Services ADWS failed to determine whether the computer is a global catalog server. What will be the solution for this.

    EventID: 1206 Event Source: Active Directory Web Services ADWS failed to determine whether the computer is a global catalog server. What will be the solution for this.

    Hi K jtm,.

    Your question of Windows is more complex than what is generally answered in the Microsoft Answers forums. It is better suited for the IT Pro TechNet public. Please post your question in the TechNet Forum. You can follow the link to your question:
    http://social.technet.Microsoft.com/forums/en/category/WindowsServer/

  • black screen that activate Windows.Windows must be enabled before validation to determine whether this copy of Windows is genuine.

    I am writing on behalf of my friend who has had his computer for a while with no problems. Today, it starts up to a black screen and then you had this message

    Windows must be activated prior to validation to determine whether this copy of Windows is genuine.
    Windows is in reduced functionality mode.

    It runs windows vista edition Home premium and it is authentic. However, it doesn't have a disc.

    can help you as he declares that he has 30 days!

    Hello

    1. is your friend able to boot to the desktop?

    2 are there hardware/software changes made on the computer, before the show?

    To analyze and solve problems for Activation and Validation, we need to see a full copy of the report produced by the MGADiag tool

    a. download and save the desktop tool

    http://go.Microsoft.com/fwlink/?LinkId=52012

    b. Once registered, run the tool.

    c. click on the continue button, which will produce the report.

    d. Paste the contents of the report in this thread.

    See also,

    How to contact a Microsoft Product Activation Center by phone

    Resolve activation problems

  • whenever I open a page, a security box appears telling me the page contains elements safe and secure, that I want to display the non secure items?

    original title: problem pop up safety box

    A couple of months, my daughter opened a video on utube.  The screen on my laptop turned blue with white writing and the volume went crazy.  Had to hold the close button.  Since then, whenever I open a page, a security box appears telling me the page contains elements safe and secure, that I want to display the non secure items?  I used for the display of this box on occasion, now it is on each page.  I ran windows security and norton scans and both find nothing.  Anyone have any ideas on how to solve this problem, because it drives me crazy.  Thanks in advance

    Hello Michelle,.

    You have a virus, here's what you need to do. Download and install malwarebytes of: http://malwarebytes.org/products/malwarebytes_free, be sure to update before running a full scan. If you cannot run the program at all, you will need to download a few programs of this site: http://www.bleepingcomputer.com/combofix/how-to-use-combofix it, you should get back on track.

    Also, you may have a browser redirection problem. Go to your IE tools--> internet options--> Connections tab, then click lan setting and make sure that the only box to checked in it is automatically detect settings.

    Let me know if it works,

    Jim

  • Determine whether the host is virtual in the groovy script

    Hello

    I am writing a groovy script to extract data from our monitored SQL Server instances.  I would like to be able to differentiate between the n & b physical and virtual hosts.  I know that this should be possible since the database dashboard displays a different icon for both.  However, I can find what data item or property I'd look for his determination.

    I use the following code:

    dataSrv = server. DataService

    querySvc = server. QueryService

    topologyQuery = «!» DBSS_Instance ".

    objects = querySvc.queryTopologyObjects (topologyQuery)

    Need a way to determine whether each object is located on a physical or virtual host

    //...........

    Thank you.

    Thank you.  That pointed me in the right direction.  For those looking for the code, I use:

    ...

    topologyQuery = «!» DBSS_Instance ".

    objects = querySvc.queryTopologyObjects (topologyQuery)

    Objects.each {object->

    instance_name = object.name

    instance_host_name = object.real_mon_instance_name

    VM = 'physical '.

    vmQuery = «!» «VMWVirtualMachine where $host.name = ' "+ instance_host_name +»»»

    VM = querySvc.queryTopologyObjects (, vmQuery)

    If (vms.size () > 0) {}

    VM = "VM".

    }

    ...

  • Determine whether the application is running

    Hello

    I'm developing an application that will provide a background thread that calls a UIApplication.

    Is there anyway that I can determine this background thread if the UIApplication is already running?

    I tried to use Application.isAlive or isForeground, but I don't have this UIApplication instance in the background thread.

    In short, can anyone suggest how to determine whether the application is running from outside the application? (excuse the sentence wrong-box )

    Thanks in advance

    Bell

    Why do you not use DURATION for this store. Take a look at this article from BB that does something similar.

    http://www.BlackBerry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800783/How_To _...

    Kind regards

    yosoh

  • How to determine whether the current operating system is windows, or MAC?

    How to determine whether the current operating system is windows, or MAC?

    CSparrow wrote:

    operatingSystem var = $.getenv ("OS");

    operatingSystem = operatingSystem.toString ();

    alert (operatingSystem);

    It gives me Windows NT Windows 10

    With the help of:

    alert($.os);
    

    works for me.

    (result: Windows/64 10.0)

    and the Silly-V code

    Folder.FS

    gives you the name of the operating system

  • How automatically update an element when another element is updated?

    How can update us an element when another element is updated in an editable form. Example: the p22_code is a LOV and 'C' is selected. We want then point p22_level to automatically run a query or plsql "select next seq... where p22_code = 'C" ".

    Published by: user10211581 on 15 Sep 2011 04:43

    APEX 3.2, you have two ways to do this.

    (1) on your item, you call a function AJAX to populate your list of selection on the onchange event. It is complex, requiring javascript and AJAX.

    (2) the simplest solution is to combine a selection with presentation box that reloads your page and run your query source in your selection box.

  • How can I determine which text fields contain data?

    Although it is a sad testament to my programming skills, I'm little embarrassed because I'm only doing this sort of thing maybe once every two or three years.  I am using FormCalc (mainly b/c I'm still learning Javascript and this form had already been written in FormCalc).

    Here's the problem:

    I have three text fields (Textfield1, Textfield2, Textfield3).

    I created three variables (var1, var2, var3) and initialized to 0.

    To determine how many fields containing data, I used the if/then/else statements:

    If (Textfield1.rawValue == "") then

    var1 = 0

    on the other

    var1 = 1

    endif

    Textfield2 and Textfield3 have similar statements (respectively using var3 and var2 variables).

    To test the code, I have a message box returns the sum of var1 + var2 and var3.  With NOTHING entered into all fields of text, I expect him back a sum of 0, but it returns the sum of 3!  If I enter data in only one or two of the fields, yet once it returns a value of 3.

    I tried the initialization of the value of the Textfields (Textfield1.rawValue = ""), but I always get a value of 3.

    This is probably a simple programming error, but still, I'm not a developer.  Any help would be appreciated.

    I think that you may need to modify your code for: (replace the "with the null value). Change of FormCalc to Javascript

    If (Textfield1.rawValue == null) then

    var1 = 0

    on the other

    var1 = 1

    endif

  • How to retrieve a value of page element in another page?

    Hello

    How to retrieve a value of page element in another page?

    say P55_COURSES_TO_EVALUATE is my name of the page element, and it is a selection list. Based on the value selected in the next page I see the details of the selected value shd and for that I need P55_COURSES_TO_EVALUATE value in the following page. How to do it? When I try to retrieve the values it simply returns nothing.
    Pointers would be really useful.

    Thanks in advance.

    Hello

    Could you please how you try to use it?

    If you set the value to the P55_COURSES_TO_EVALUATE element and submit the page, the value is stored in session state.
    Then you can use this element in any page as

    :P55_COURSES_TO_EVALUATE
    

    You cannot access page value in javascript/jQuery to other pages like

    $v('P55_COURSES_TO_EVALUATE')
    document.getElementbyID('P55_COURSES_TO_EVALUATE')
    $(#P55_COURSES_TO_EVALUATE)
    

    Because the item is not on the other pages. In javascript from other pages, you can use

    var a = '&P55_COURSES_TO_EVALUATE.';
    

    Kind regards
    Jari

  • How to build an extensible array of elements of another array

    I try to have a subset of the table #1 (iteration 0) repeated simultaneously for all iterations and form table #2.

    Here's what I'm trying to have:

    (See file attached .png)

    Thanks in advance!

    Here, this can help:

  • How to create the container element using Vi types in teststand

    Hello

    I want to create containers in the Array element in teststand, which different downhill element. for example I like, .txt file

    Name height, age, color

    A, 20, 186, black

    B, 30 170, white

    first line should be elements of the container, and the second line should be the value of the element. Raising must be string, number or boolean.

    Then, in the second container to new element in the first row and value in the third row.

    And all this container must be below the table of the fileglobals element or people of the country.

    Is there any suggestions how?

    Thank you much in advance.

    Kind regards

    Ankit.

    Hi Pierre,.

    I edited your VI test and successfully wrote the table of container to a variable existing non "Locals.dummy99" (see screenshot).

    Best regards

    Christoph

  • Get the container element

    I created a container that contains numbers and strings of elements. I would like to pass the one element to a vi. But I don't know how to extract the element respectively.

    Is there a way to get the items in the container one by one? Something like: Array [1], Array [i + 1] will simply work for table, but that any container? I can't do [i] container. It will return the error.

    Thank you very much in advance!

    Once you get container.element_name in a variable example: locals.tempstr = "cont.str1".

    Use the below function to get the value.

    Locals.Str = RunState.main.locals.GetValVariant (locals. TempStr, 0)

    It works for the number, and string - chosen variant to this end.

    For numeric values, you can use val (locals.str) to convert the numeric type.

    There should be a way to get the type of variable. Will explore further and let you know.

    I hope this helps.

Maybe you are looking for

  • iPhone cannot be synced in iTunes

    When I connect my iPhone 6 more to my iMac, I get the above message.  It has not saved or synchronized for a long time now.  I thought maybe would it IOS 9.3.1 but it always does after the update to 9.3.2. Any suggestions? Thank you

  • I can not register to use the firefox forums

    When you get to the sign or save page it puts you right in a loop for the sign to the top of the page without the possibility to register. I was finally able to register by submitting this issue. You can fix this.

  • Display of the current process

    I am currently a manual backup on USB. The records, I'm moving are large and the process for the first folder is the estimate of 10 hours on the web administration page. My question is if I close the web administration and then page reload the bar of

  • Linking a Varable shared several MODBUS registers

    A simple question, but can't seem to find an answer: I have a library project with a configuration of server i/o MODBUS series. In this library, I have several shared variables that are related to the registers on the remote device via the MODBUS Pro

  • Find cell that caused the event change of value on table

    Hello I have a table, it is essentially a 2D channels table... I have a case of the event, he put in place to trigger if there is a change in value on my table.  Anyone know how can I know what my case of the event enabled cell? What element of the a