Determining if element is in a certain array

Hi,
I was wondering if there is a way to determine if a String element is part of an array of Strings. In other words, I want to do something like:
String myString = "blah";
String[] stringArray = {"blah", "foo"};
if (myString is part of stringArray) {
// Do stuff here
}The reason I want to do this is because I have two large String arrays, and want to determine if a String element is in one array or the other, and do some stuff based on the result.
Is there a way to do this? If so, how? Could I use compareTo, or something like that, to determine if it is part of an array?
Thanks,
Dan

Use java.util.Arrays.binarySearch(stringArray, myString) if the array is sorted, or use a more high-powered collection class instead (such as a java.util.ArrayList, and the methods it provides to search within).
http://java.sun.com/j2se/1.5.0/docs/api/index.html

Similar Messages

  • Is there a way of determining what element in an array is being clicked on?

    Hi all.  I would like to setup an event to determine what element in an array is being clicked on/hovered over.  I think I tried this before and found it wasn't working due to limitations of LV 7.0.  If this code already exists, it would be great if I don't have to do a scavenger hunt for the solution.
    I think one possibility I nixed was to use the refnum of the elements to determine which one it is.  IIRC, this is not possible because the refnum of the element is for the edit box only.
    The second possiblity is to get the on click event, and somehow determine which element in the array it is.  This doesn't sound too difficult as it should be a simple calculation, but may get in to some hairryness based on if the indicies are visible or not, and if I am using a new or old array with new or old control (calc would change based on boarder size of the controls).  I might just simplify it by removing indicies and using older control set which has minimal boarder size.
    And just for fun, can I force a tool tip to show up?
    Thanks all,
    A
    Using LV7.0 on WinXP.

    blawson wrote:
    Been bitten by LabVIEW wrote:
    I think one possibility I nixed was to use the refnum of the elements to determine which one it is.  IIRC, this is not possible because the refnum of the element is for the edit box only.
    Using LV7.0 on WinXP.
    This is indeed possible, at least in the newer versions I use.
    Take the array refnum from the click event data terminal and get a reference to the array element.  This refers to the element that was clicked, but you do need to work out how to get the index.  My method is to use property nodes to get the screen position and size of the element and the screen position and size of the array, as well as the array's Visible Index property. For each direction, take the quotient of the relative position of the element (account for padding!) over the size of an element.
    I suspect that taking the mouse coords and comparing to the array's sizes in pixels is similar, although I trust my method for events that don't have mouseclicks (what coords does Array:shortcut menu selection(User) return if you used the keyboard?)
    Here's an old version I happened to have open.  I've posted about this before, I suspect I have a clearer version in my gallery.  I use this method in my example code contest entry to work out which square of the chessboard is clicked.
    Thank you for that one!
    I am currently "locked up behind a down-rev fence" (working an old app in an old version) so I had not heard of that.
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • How to display last element in a dynamic 1d array

    hi..
    i want to display the value of last element in a 1d dynamic array.../ i mean ..if i stop the vi run, i need to display the last element in the array..how can i do this?
    and is there any way to use a button to start the vi...instead of using the Run button on the vi front panel??
    Solved!
    Go to Solution.

    Index array!.  Use array size to determine the size of your array, subtract 1, feed that in the index terminal of Index Array.
    You have to start the VI running somehow.  It could be set to run when opened.  Assuming what you want is a means to type values into a front panel, hit a GO button that you created on the front panel, then have the real part of the VI execute.  You could use an event structure.  Or put a while loop at the beginning with a small wait statement in side that basically just polls the GO button.  When that button is pressed, the true boolean stops the while loop and allows the program to proceed to the main body of your program.

  • How do I convert a 1-D array of cluster of 5 elements into a 2-D array of numbers? (history data from a chart)

    Hello,
    in my vi I have a chart with 5 Plots displaying measurement data.
    The user should be able to save all the history data from the chart at anytime. (e.g. the user watches the chart and some event happens, then he presses a "save"-button)
    I know, that I can read out the history data with a property node. That is not the problem. The problem is, how do I handle the data? The type of the history data is a 1-D array of cluster of 5 elements.
    I have to convert that data somehow into a 2 D-array of numbers or strings, so that I can easily save it in a text-file.
    How do I convert a 1-D array of cluster of 5 elements into a 2-D array of numbers?
    I use LabVIEW 7.1
    Johannes
    Greetings Johannes
    Using LabVIEW 7.1 and 2009 recently
    Solved!
    Go to Solution.

    Gerd,
    thank you for the quick response and the easy solution.
    Look what I did in the meantime. I solved the problem too, but muuuch more complicate :-)
    And I have converted the numbers to strings, so that I can easily write them into a spreasheet file.
    Johannes
    Message Edited by johanneshoer on 04-28-2009 10:39 AM
    Greetings Johannes
    Using LabVIEW 7.1 and 2009 recently
    Attachments:
    SaveChartHistory.JPG ‏57 KB
    SaveChartHistory.JPG ‏57 KB

  • Set number of elements in a two dimensional array

    Hi,
    Does anyone know how to set the number of elements in a two dimensional array directly in teststand.
    To set a one dimsional array is simple:
    SetNumElements( locals.somearray,4)
    Is there a method to do this for a two dimensional array?
    Sean

    From the help file (TestStand 4.2.0):
    PropertyObject.SetNumElements
    SetNumElements Method
    Syntax
    PropertyObject.SetNumElements ( numElements, options = 0)
    Purpose
    Sets the number of elements of a single dimensional array.
    Remarks
    This method is only valid for single dimensional arrays. The elements in the array retain their values. Use the PropertyObjectType.ArrayDimensions property to set the number of elements in each dimension of a multi-dimensional array.
    Parameters
    numElements As Long
    [In] New number of elements for the array.
    options As Long
    [In] Pass 0 to specify the default behavior, or pass one or more PropertyOptions constants. Use the bitwise-OR operator to specify multiple options.
    This parameter has a default value of 0.
    So you could use, for example: Locals.MultidimensionalArray.Type.ArrayDimensions.SetBounds({1,0},{3,4}) to set an array to have three dimensions (1,2,3), each with five elements (0,1,2,3,4).

  • I set my printing size on PS Elements 10 for a certain size, but it prints 1/4 inch larger?

    I set my printing size on PS Elements 10 for a certain size, but it prints 1/4 inch larger?

    In addition of Hatstead suggestion my Suggestions are  following:
    1. From your Printer's Preferences uncheck the Borderless check box (if checked already).
    2. After launching the Print dialog, click on More Option button, then under Printing choice tab make sure that Border section has all check box unchecked.
    3. Uncheck the "Crop to Fit" check box if it is checked.
    -Tywin

  • Determining what views are created for certain structure

    Hi!
    I need to create some views to structure in Development system as it is done in Production system already. It is something like manual transfer of structure and it's views from Production to Developement system (special case).
    My question is this: how to determine what views are created for certain structure?
    Will reward,
    Mindaugas

    Use 'Where-used' list for that structure.
    Go to SE11.
    Enter the structure name.
    click on the Where-used list button in the toolbar.
    Select the applicable options. (In your case 'Views')

  • Does any body know how to replace a chunk of elements in a 2-D array

    I have a vi that I am working on that needs to be able to replace a lot of elements and I would like to replace them all with 1 operation. thanks in advance vivi

    I you want to replace a "rectangle" inside a 2D array, you can wire a 2D array into the element input of the Replace Array Subset. In that case, the index you wire into the function will specify where you start the replacing.
    Try to take over the world!

  • JSF: How to determine which element has the focus?

    Hi all,
    I have a JSP with some input fields and a text area. When I press "ENTER" the data I have entered should be saved. That works fine (I use JavaScript to catch the keyPressed-event). But when I want to insert a new line in the text area, I press ENTER too and this invokes the javascript function. So it�s not possible to insert a new line in the text area. And I don`t want to save the data when I�m just inserting a new line.
    is it possible to determine which element has the focus at the moment of pressing ENTER? if it`s the text area then I won�t save the data and inserting a new line is possible? Or how to say: "Insert an new line if the user presses SHIFT+ENTER" or something like that?
    I�m using JSC for my application and this is my JS-function:
    function checkIt(evt)      
    var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
         if (charCode == 13)
              document.getElementById('form1:bt_Save').click();
              return false;
              return true;
    I�m looking for something like that:
    if(charCode == 13) {
    if(document.getElementById('form1:textArea').hasFocus())
    doNothing...
    else {
    document.getElementById('form1:bt_Save').click();
         return false;
    thanks for any help

    Hi,
    I searched through many forums (js of course too) but
    I couldn�t find a solution. Everybody knows how to
    set the focus but not how to get it. We often use
    JSF/JSP with javascript and maybe somebody here has
    another approach to this problem (how to solve it
    using jsf itself or anything else)?Take easy. I just suggested to search in a JavaScript forum , in your question you didn't mentioned this. Good luck man.
    Cya.

  • How do I determine what element in an array was right clicked on?

    I have an array set up on my front panel. When the user right clicks on an element in that array, I would like them to be able select from 3 different options. I have the shortcut menu working, but I need to know which element in the array the user right clicked on to determine what values to change. How can I get the index of the element?
    Thanks for any help!
    Solved!
    Go to Solution.

    Couldn't you get index values from the array property node?
    Also this doesn't account for if scrollbars are seen or not.  And I usually like to know if my range is valid, because again I could be clicking on a scrollbar, or label and still get the Mouse Down event.
    Here is one I posted a while ago.
    http://forums.ni.com/t5/LabVIEW/Interesting-way-to-detect-array-index-from-mouse-position/m-p/286841...
    Unofficial Forum Rules and Guidelines - Hooovahh - LabVIEW Overlord
    If 10 out of 10 experts in any field say something is bad, you should probably take their opinion seriously.

  • Put certain elements of an arraylist of arrays into a hashset

    I have an arraylist of arrays. I now need to create a separate list that contains unique combinations of only 3 values contained in the underlying array in the arraylist. I think I can use a HashSet. I am just not sure how to create the HashSet?
    I could create an ArrayList of just those 3 values and then use the add method but again I'm not sure how to create the ArrayList based on sub-elements of the original ArrayList. (i.e. copy three "variables" from the array in the arraylist to the new array for each member of the arraylist.)
    Any help would be greatly appreciated.

    Let us just say I want to. I would prefer a solution to my original problem. Comments asking (well exclamation points are more "demand" then "ask") for justification are irrelevant to my solution. Just work with the problem I have please. Thanks.
    Again. I have an arraylist of arrays. I would like to create a nonduplicate subset of only 3 members of the arrays contained in the arraylist. I believe a hashset will do this.
    I have tried this as a test..trying to make a hashset of two subelements:
          HashSet hs = new HashSet();
          for (int counter=0; counter<allocations.size(); counter++)
             hs.add({((double[])allocations.get(counter))[1], ((double[])allocations.get(counter))[2]});
          ..but unfortunately I get this error:
    mcp.java:227: illegal start of expression
    hs.add({((double[])allocations.get(counter))[1], ((double[])allocations.get(counter))[2]});
    ^
    mcp.java:227: ')' expected
    hs.add({((double[])allocations.get(counter))[1], ((double[])allocations.get(counter))[2]});
    ^
    so I am obviously not putting the hashset together correctly.

  • Nested IPE (In Place Element) usage when accessing Cluster/Array data via DVR

    I am sharing data across several VIs and loops via a DVR, and accessing the data via a DVR IPE. The data is a cluster of arrays. The diagram below (VI attached) illustrates the structures invloved, but not the structure of the application.
    (The diagram above does not include initialization of the arrays, as it is intended only to illustrate the Cluster1 data type. Array lengths could be 100.)
    The DVR (DVR1) is passed to multiple VIs of the application at startup.
    Each VI executes loops that either read or write particular elements of each array (fArray1 or fArray2).
    I believe the DVR IPE (B1-DVR) provides blocking so that only one task can modify the data (Cluster1) at any time.
    Case 1 illustrates how I currently WRITE to array elements. The outer IPE (block B1) is rolled into a VI (not shown) that takes DVR1, Index, and Value as inputs.
    Cases 2 - 4 illustrate 3 additional methods that remove one or both of the inner IPEs (B2-Cluster and B3-Array).
    Case 2: IPE B3 (Array Index/Replace Elements) is replaced with a non-IPE 'Replace Array Subset'.'
    Case 3: IPE B2 (Unbundle / Bundle Elemnts)' is replaced with a non-IPE cluster 'Unbundle'/'Bundle'.
    Case 4: removes both B2 and B3.
    I implemented case 1 a long time ago.  When I had to do the same thing again recently, I did case 4.  When I stumbled across my earlier implementation, I was a bit suprised
    Which of the 4 cases should take the least time (or resources) to execute? I think case 4 has as few array allocations as any of the other 3.
    The attached image did not capture the Buffer Allocation marks, so I marked the ones that differed with a red "B".
    I am only interested in differences in how the arrays are handled, so I see no signioficant differences.
    Is this one of those cases where LV doesn't need my help?
    Incidently, I recently wrote a small app with shared data and decided to try FGVs to share array data.  For small arrays, 10^7 iterations, and an FGV based array-element read followed by a element write, the FGV was faster.  1.2us per read/write for FGV vs 3us per r/w for an DVR/IPE based read/write (like above).
    Peter
    LV 2011 SP1, Windows 7 64-Bit
    Attachments:
    IPE.vi ‏9 KB

    Option 1 is a definite no and as far as I know it has been NI's explicit intention to steer clear from it. I believe there's an idea in the IE which asks for this.
    I agree that option 2 makes sense, but I don't think it should be something the user specifies. Either LV can detect it automatically or it can't, but I doubt NI would let you have an option which creates the possibility for this kind of bug.
    I'm not sure, but the mark as modifier option on the IPES might be the option you're looking for. I know that it exists and I know very roughly what it does, but the documentation for it is very limited and I never actually played around with it, as usually I don't need these kinds of optimizations.
    You may well be right that a new option on the IPES is desirable and you should probably add it to the idea exchange.
    As for NIWeek, I'm not going this year, so I have no idea what kinds of sessions are around, but it's a great place to find people who know what they're talking about and ask them about it directly. Certain people in LV R&D would probably be ideal for this and if you ask relevant people, you might even get their names. I'm sure buying them a beer would also help to loosen their tounges. If you ask me, this type of interaction is the main value of the conference, not the sessions themselves.
    Try to take over the world!

  • How can I remove only the middle elements from a 2-D array?

    Hello all!
    We have had an issue at my work where some of our graphs featuring a Gaussian curve have an unusual rectangular distortion in the middle of the curve (sorry that I have no image to show you, the error is before my time at the company, and I've been asked to find a solution before it happens again). Basically, what should be a Gaussian curve is leveling off briefly and looking like a rounded square wave. We know what causes the distortion, so I only wish to remove the middle part, giving it the appearance of a Gaussian. It's odd, but it actually offers a good approximation of what we want. The graph is made from a 2-D array of Double values, and we can estimate the size of the leveled-area, so I figured that removing the middle elements from the graph would accomplish this. Does anybody know a way I can accomplish this?
    -Gobble
    LabView 8.5.1

    Raven,
    Thank you very much, I'll try that!
    -Gobble
    LabView 8.5.1

  • Is there a way to determine all the function of a certain dll in Labview?

    Hi, I am Marlon. Is Labiew capable of determining all function in a certain DLL?

    Hi Marlon.
    There is a example in Labview Zone ( look for "Get DLL Exports") that lists names of all functions in a dll 32.
    Hope it helps
    Alipio
    "Qod natura non dat, Salmantica non praestat"

  • How to determine the user who placed a certain concurrent request?

    Hi there,
    Is there a way (SQL query, for example) that can help me determine the user (EBS username) who placed a certain concurrent request?
    Thanks,
    Tareq

    Hi Tareq;
    Please check below notes which could be helpful for your issue:
    Concurrent Request-whcih is submmited by one of the Oracle USER *<<Posted By Hussein Sawwan*
    How to See Others Concurrent Request Oracle 11i
    Concurrent program- How to find database session *<<Posted By Hussein Sawwan*
    Re: Reg: Apps Concurrent
    Regard
    Helios

Maybe you are looking for