Using indexOf( ) to search arrays

I would like to know, can you get an index of an array? for example, if I have typed:
String ay = "A";
String[] numArray = { "A", "B", "C", "D", "E", "F" }
, can I then write:
if (ay.indexOf("A") != -1) {
do-something
else {
do-something-else
if this is possible, it would certainly save me a lot of time when performing validation!

There is a static method binarySearch in java.util.Arrays. Guess it does what you need.
I would like to know, can you get an index of an
array? for example, if I have typed:
String ay = "A";
String[] numArray = { "A", "B", "C", "D", "E", "F" }
, can I then write:
if (ay.indexOf("A") != -1) {
do-something
else {
do-something-else
if this is possible, it would certainly save me a
lot of time when performing validation!

Similar Messages

  • Search Text in a TextBox using IndexOf

    Rather than using Regular Expression I want to know how I can use LastIndexOf and IndexOf to search for the Next and Previous match of a word typed. I want to use a TextBox and not a RichTextBox. Can someone provide me with a way to do this using loop so
    it gets all the matches. I've got this so far:
    Public Function FindAndSelect(TextToFind As String, MatchCase As Boolean) As Boolean
    Dim mode = If(MatchCase, StringComparison.CurrentCulture, StringComparison.CurrentCultureIgnoreCase)
    Dim position As Integer = textBox1.Text.IndexOf(TextToFind, mode)
    If position = -1 Then
    Return False
    End If
    textBox1.SelectionStart = position
    textBox1.SelectionLength = TextToFind.Length
    TextBox1.Select()
    Return True
    End Function
    MessageBox.Show("Hey You!")

    Rather than using Regular Expression I want to know how I can use LastIndexOf and IndexOf to search for the Next and Previous match of a word typed. I want to use a TextBox and not a RichTextBox. Can someone provide me with a way to do this using loop so
    it gets all the matches. I've got this so far:
    Public Function FindAndSelect(TextToFind As String, MatchCase As Boolean) As Boolean
    Dim mode = If(MatchCase, StringComparison.CurrentCulture, StringComparison.CurrentCultureIgnoreCase)
    Dim position As Integer = textBox1.Text.IndexOf(TextToFind, mode)
    If position = -1 Then
    Return False
    End If
    textBox1.SelectionStart = position
    textBox1.SelectionLength = TextToFind.Length
    TextBox1.Select()
    Return True
    End Function
    MessageBox.Show("Hey You!")
    Hello,
    For Next, we could get that done with following way since we could select start index, you could refer to
    String.IndexOf Method (String, Int32, StringComparison).
    Dim startPostion As Integer = 0
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim str As String = "1"
    ' Dim mode = If(StringComparison.CurrentCulture, StringComparison.CurrentCultureIgnoreCase)
    If startPostion + str.Length > TextBox1.Text.Count Then
    Return
    End If
    Dim position As Integer = TextBox1.Text.IndexOf("1", startPostion, StringComparison.CurrentCultureIgnoreCase)
    If position = -1 Then
    Return
    End If
    TextBox1.SelectionStart = position
    TextBox1.SelectionLength = str.Length
    startPostion = position + str.Length
    TextBox1.Select()
    End Sub
    The part about previous is quite similar, you could edit it to suit your scenario.
    Regards,
    Carl
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Binary search tree in java using a 2-d array

    Good day, i have been wrestling with this here question.
    i think it does not get any harder than this. What i have done so far is shown at the bottom.
    We want to use both Binary Search Tree and Single Linked lists data structures to store a text. Chaining
    techniques are used to store the lines of the text in which a word appears. Each node of the binary search
    tree contains four fields :
    (i) Word
    (ii) A pointer pointing to all the lines word appears in
    (iii) A pointer pointing to the subtree(left) containing all the words that appears in the text and are
    predecessors of word in lexicographic order.
    (iv) A pointer pointing to the subtree(right) containing all the words that appears in the text and are
    successors of word in lexicographic order.
    Given the following incomplete Java classes BinSrchTreeWordNode, TreeText, you are asked to complete
    three methods, InsertionBinSrchTree, CreateBinSrchTree and LinesWordInBinSrchTree. For
    simplicity we assume that the text is stored in a 2D array, a row of the array represents a line of the text.
    Each element in the single linked list is represented by a LineNode that contains a field Line which represents a line in which the word appears, a field next which contains the address of a LineNode representing the next line in which the word appears.
    public class TreeText{
    BinSrchTreeWordNode RootText = null;// pointer to the root of the tree
    String TextID; // Text Identification
    TreeText(String tID){TextID = tID;}
    void CreateBinSrchTree (TEXT text){...}
    void LinesWordInBinSrchTree(BinSrchTreeWordNode Node){...}
    public static void main(String[] args)
    TEXT univ = new TEXT(6,4);
    univ.textcont[0][0] = "Ukzn"; univ.textcont[0][1] ="Uct";
    univ.textcont[0][2] ="Wits";univ.textcont[0][3] ="Rhodes";
    univ.textcont[1][0] = "stellenbosch";
    univ.textcont[1][1] ="FreeState";
    univ.textcont[1][2] ="Johannesburg";
    univ.textcont[1][3] = "Pretoria" ;
    univ.textcont[2][0] ="Zululand";univ.textcont[2][1] ="NorthWest";
    univ.textcont[2][2] ="Limpopo";univ.textcont[2][3] ="Wsu";
    univ.textcont[3][0] ="NorthWest";univ.textcont[3][1] ="Limpopo";
    univ.textcont[3][2] ="Uct";univ.textcont[3][3] ="Ukzn";
    univ.textcont[4][0] ="Mit";univ.textcont[4][1] ="Havard";
    univ.textcont[4][2] ="Michigan";univ.textcont[4][3] ="Juissieu";
    univ.textcont[5][0] ="Cut";univ.textcont[5][1] ="Nmmu";
    univ.textcont[5][2] ="ManTech";univ.textcont[5][3] ="Oxford";
    // create a binary search tree (universities)
    // and insert words of text univ in it
    TreeText universities = new TreeText("Universities");
    universities.CreateBinSrchTree(univ);
    // List words Universities trees with their lines of appearance
    System.out.println();
    System.out.println(universities.TextID);
    System.out.println();
    universities.LinesWordInBinSrchTree(universities.RootText);
    public class BinSrchTreeWordNode {
    BinSrchTreeWordNode LeftTree = null; // precedent words
    String word;
    LineNode NextLineNode = null; // next line in
    // which word appears
    BinSrchTreeWordNode RightTree = null; // following words
    BinSrchTreeWordNode(String WordValue)
    {word = WordValue;} // creates a new node
    BinSrchTreeWordNode InsertionBinSrchTree
    (String w, int line, BinSrchTreeWordNode bst)
    public class LineNode{
    int Line; // line in which the word appears
    LineNode next = null;
    public class TEXT{
    int NBRLINES ; // number of lines
    int NBRCOLS; // number of columns
    String [][] textcont; // text content
    TEXT(int nl, int nc){textcont = new String[nl][nc];}
    The method InsertionBinSrchTree inserts a word (w) in the Binary search tree. The method Create-
    BinSrchTree creates a binary search tree by repeated calls to InsertionBinSrchTree to insert elements
    of text. The method LinesWordInBinSrchTree traverses the Binary search tree inorder and displays the
    words with the lines in which each appears.
    >>>>>>>>>>>>>>>>>>>>>>
    //InsertionBinTree is of type BinSearchTreeWordNode
    BinSrchTreeWordNode InsertionBinSrchTree(String w, int line,                                             BinSrchTreeWordNode bst)
    //First a check must be made to make sure that we are not trying to //insert a word into an empty tree. If tree is empty we just create a //new node.
         If (bst == NULL)
                   System.out.println(“Tree was empty”)
         For (int rows =0; rows <= 6; rows++)
                   For (int cols = 0; cols <= 4; cols++)
                        Textcont[i][j] = w

    What is the purpose of this thread? You are yet to ask a question... Such a waste of time...
    For future reference use CODE TAGS when posting code in a thread.
    But again have a think about how to convey a question to others instead of blabbering on about nothing.
    i think it does not get any harder than this.What is so difficult to understand. Google an implementation of a binary tree using a single array. Then you can integrate this into the required 2-dimension array for your linked list implemented as an array in your 2-d array.
    Mel

  • How to split a string using IndexOf?

    How would you split a string using indexOf and not using the .split method?
    Any help is appreciated :D
    Message was edited by:
    billiejoe

    would it be better to use the first or the second?
    int      indexOf(int ch)
    Returns the index within this string of the first occurrence of the specified character.
    int      indexOf(int ch, int fromIndex)
    Returns the index within this string of the first occurrence of the specified character, starting the search at the specified index.
    I think the second would be helpful. so how do i read it?

  • Search Array with multiple values

    Hello,
    I've been helped with the prototype below by blemmo (thanks).
    It allows me to search my array using one property == a
    value.
    Now, I'd like to use it to:
    if ((prop1 == val1) &&(prop2 == val2) &&
    (prop3 == val3) {
    // search array for all values in array with the values of
    val1, val2 and val3
    Also, a way to search if one of the prop and val's are blank,
    ie...
    ((prop1 == val1) &&(prop2 == val2) && (prop3
    == val3)
    where prop2 and val2 are "undefined"
    so the search will only search for the prop and val that are
    not "undefined"
    make since? Don't know where to start.
    help and thanks in advance.

    it is an array like this.. but with more properties... also,
    is it better to use XML to load large arrays or is it ok to use
    actionscript in the file.
    which is faster to load? say if I had an array of 150
    elements?
    myArray = [{myname:"bob", county:"skagit", city:"Sedro
    Woolley", id:1,
    pic:"1.jpg",pic1:"2.jpg",pic2:"3.jpg",pic3:"4.jpg"},
    {myname:"bob", county:"skagit", city:"Sedro Woolley", id:1,
    pic:"1.jpg",pic1:"2.jpg",pic2:"3.jpg",pic3:"4.jpg"

  • IndexOf on multidimensional array

    var clipArray:Array = new Array();
    clipArray[0] = new Array();
    clipArray[1] = new Array();
    clipArray[0][0]=2
    clipArray[0][1]=3
    clipArray[1][0]=4
    clipArray[1][1]=5
    trace(clipArray[0].indexOf(3));
    This traces '1' cause 3 can be found in [0][1] of the multidimensional array and 1 is the second value of that 0.
    Using indexOf this way I can determine that second value in which in this case the value 3 can be found.
    I want to to take this one step further and use indexOf somehow to determine the first value of the clipArray variable. So looking for 2 or 3 should trace 0 and looking for 4 or 5 should trace 1. Is there some way to do this?

    the following returns both indices:
    function indexOf2D(a:Array,v:*):Array{
    for(var i:int=0;i<a.length;i++){
    for(var j:int=0;j<a[i].length;j++){
    if(a[i][j]==v){
    return [i,j];
    return [-1,-1];

  • How can I use ONE Text search iView to event/affect mutliple Result Sets?

    hello everyone,
    i have a special situation in which i have 6 flat tables in my repository which all have a common field called Location ID (which is a lookup flat to the Locations table).
    i am trying to build a page with a free-form text search iView on Table #1 (search field = Location ID).  when I execute the search, the result set for Table #1 is properly updated, but how do I also get Result Set iViews for Tables #2-6 to also react to the event from Text Search for Table #1 so that they are updated?
    i don't want to have to build 6 different text search iViews (one for each table).  i just want to use ONE text search iView for all the different result set tables.  but, in the documentation and iView properties, the text search iView doesn't have any eventing.
    if you have any suggestions, please help.
    many thanks in advance,
    mm

    hello Donna,
    that should not be a problem, since you are detailw with result sets and detail iviews because custom eventing can be defined for those iviews.
    Yes, it says "no records" found because an active search and record selection havent' been performed for it (only your main table does).
    So, yes, define a custom event, and pass the appropriate parameters and you should be fine.
    Creating a custom event between a Result Set iView and an Item Details iView is easy and works. I have done it.
    See page 35 of the Portal Content Development Guide for a step-by-step example, which is what I used.
    For my particular situation, the problem I'm having is that I want the Search Text iView's event (i.e., when the Submit button is pressed) to be published to multiple iViews, all with different tables.  Those tables all share some common fields, which is what the Search iView has, so I'd like to pass the search critera to all of the iViews.
    -mm

  • HT6114 Can't save downloads to existing files??  In the "save as" box I use the little "search" window to locate where I want to put a new file but when found the location file does not operate.  And dropdown menu says "save to online acct"

    When I try to save an emailed-to-me document to an existing file on my hard drive by using the little "search" window the recipient file is inactive and does not open to recieve the document I want to save (nothing happens when I click on it and it's a subdued color).
    If I click through my files manually by starting on the desktop and working my way to the location of the recipient file I can save.
    This takes a lot of time and is DRIVING ME CRAZY!
    Please tell me I've just missed something obvious that can be fixed in a jiffy!?

    OMG!!  It also happens when I try to open a file from inside a program like Adobe Reader.  If I use the little corner search window all the files are inoperable.

  • How can I use two single-dimensional arrays-one for the titles and array

    I want to Use two single-dimensional arrays-one for the titles and one for the ID
    Could everyone help me how can i write the code for it?
    Flower
    public class Video
    public static void main(String[] args) throws Exception
    int[][] ID =
    { {145,147,148},
    {146,149, 150} };
    String[][] Titles=
    { {"Barney","True Grit","The night before Christmas"},
    {"Lalla", "Jacke Chan", "Metal"} };
    int x, y;
    int r, c;
    System.out.println("List before Sort");
    for(c =0; c< 3; ++c)
    for(r=0; r< 3; ++ r)
    System.out.println("ID:" + ID[c][r]+ "\tTitle: " + Titles[c][r]);
    System.out.println("\nAfter Sort:");
    for(c =0; c< 3; ++c)
    for(r=0; r< 3; ++ r)
    System.out.println("ID:" + ID[c][r]+ "\tTitle: " + Titles[c][r]);

    This is one of the most bizarre questions I have seen here:
    public class Video
    public static void main(String[] args) throws Exception
    int[] ID = {145,147,148, 146,149, 150};
    String[] Titles= {"Barney","True Grit","The night before Christmas", "Lalla", "Jacke Chan", "Metal"};
    System.out.println("List before Sort");
    for(int i = 0; i < Titles.length; i++)
       System.out.println("ID:" + ID[i]+ "\tTitle: " + Titles);
    System.out.println("\nAfter Sort:");
    for(int i = 0; c < Titles.length; i++)
    System.out.println("ID:" + ID[i]+ "\tTitle: " + Titles[i]);
    Generally you don't use prefix (++c) operators in you for loop. Use postfix (c++).
    Prefix means that it will increment the variable before the loop body is executed. Postfix will cause it to increment after.

  • How to use ADF Query search with EJB 3.0

    Hi,
    In ADF guide http://download.oracle.com/docs/cd/E12839_01/web.1111/b31974/web_search_bc.htm#CIHIJABA
    The steps to create query search with ADF Business Components says:
    "+From the Data Controls panel, select the data collection and expand the Named Criteria node to display a list of named view criteria.+"
    But with EJB, I'm not able to find Named Criteria node. Can we use ADF query search component with EJB? If yes, can you please show me some example, tutorial etc.?
    Thanks
    BJ

    For EJBs you'll need to implement the query model on your own.
    An example of how the model should look like is in the ADF Faces components demo.
    http://jdevadf.oracle.com/adf-richclient-demo/faces/components/query.jspx
    Code here:
    http://www.oracle.com/technology/products/adf/adffaces/11/doc/demo/adf_faces_rc_demo.html

  • Is there any way to search for a term using the Firefox search field, and have the results automatically open in a new tab?

    Is there any way to search for a term using the Firefox search field, and have the results automatically open in a new tab? When there was support for Google Toolbar, I was able to do this; now, whenever I want to search for something, I have to open a new tab to do it, and cut-and-paste my search into the search field in the new tab. I used to be able to highlight, drag, and drop something into the search field and have it automatically open in a new tab. This is enough for me to switch to Chrome . . .

    Set a preference to have searches from the Search Bar (upper right) automatically open all searches in a new tab
    #type '''about:config''' in the URL/Location/Address bar and press the Enter key
    #if you see a warning, accept it (promise to be careful)
    #Filter = '''browser.search.openintab'''
    #in the lower panel, double click the item (or right-click and choose "Toggle") to change the value to "true"
    #close the about:config tab and test
    #See:
    #*For help with opening/using about:config, also see: http://kb.mozillazine.org/About:config
    #*Also see: http://kb.mozillazine.org/About:config_entries (click on "Browser", scroll down to browser.search.openintab)
    '''Search Bar''': http://support.mozilla.com/en-US/kb/Search+bar
    '''If this reply solves your problem, please click "Solved It" next to this reply when <u>signed-in</u> to the forum.'''
    About Google toolbar............
    Google decided that they will no longer produce the Google Toolbar for Firefox 5 and newer version. It is best to move on to other alternatives than to try any "hacks" to the toolbar that may or may not perform in the future. Future versions of Google toolbar will only work with IE7-9. Google Toolbar is not available on any other browser, even Google's own browser.
    *http://googletoolbarhelp.blogspot.com/2011/07/update-on-google-toolbar-for-firefox.html
    *https://support.mozilla.com/en-US/kb/google-toolbar-not-compatible-firefox?s=google+toolbar&r=0&as=s
    *http://www.google.com/support/toolbar/bin/answer.py?answer=1342452&topic=15356%29
    *Google Toolbar 8 FAQ (IE only): https://www.google.com/support/toolbar/bin/answer.py?hl=en&answer=1111588
    '''''To access your Google Bookmarks visit''''' www.google.com/bookmarks.
    Alternatives:
    *http://kb.mozillazine.org/Using_Google_Toolbar_features_without_toolbars
    *https://addons.mozilla.org/en-US/firefox/addon/googlebar-lite/
    *https://addons.mozilla.org/en-US/firefox/addon/gbookmarks-google-bookmarks-fo/

  • Windows 8.1 PC, using reader, when searching a folder containing approx 100 doc's. If i search for a word, no results are returned. only the doc names can be found but nothing from within the doc. This is a new problem and was not the case before.

    Windows 8.1 PC, using reader, when searching a folder containing approx 100 doc's. If i search for a word, no results are returned. only the doc names can be found but nothing from within the doc.
    This is a new problem and was not the case before.

    Works perfectly fine for me with the latest Reader version (11.0.09).
    You write that it worked "before"; before what?  An update?  Update from what version to what version?

  • Sometimes when using the Google search engine, after using the Back button in the Firefox 4.0.1 browser, I am no longer able to click in the Google search box.

    Sometimes when using the Google search engine, after using the Back button in the Firefox 4.0.1 browser, I am no longer able to click in the Google search box.
    This problems has been occurring on two different machines over the last two days.

    I think this may not be a browser problem but rather a Google problem.
    I am getting the same problem with the Google Chrome browser.

  • Search help for Web Dynpro using the SAP-search help

    Hi,
    I’m trying to create a generic search help for Web Dynpro using the SAP-search help. It should working so, that I construct a Web Dynpro-component, that gets the data of the search help from the SAP-system, interpreted it and creates the ui-elements and the needed context generic.
    The mapping between the Input field of the customerview and the right search help is to be made with an xml-file, which contains the information: name of the view, the input field, the search-help-name and the name of the field that will be returned.
    The xml-file is reading from a helper-class. That helper-class contains any information, witch need the search help-component as well as the customer-component.
    The initialization takes place in the method wdDoModify of the customer. The call of the search help from the customer should be implement with an Action, witch is bound to a Button(create dynamic in the helper-class behind the input field).
    In a second foot should be create a plugin for eclipse, witch insert the used files (search help component, helper class, …) in the project. In addition it should create the call in the customer generic.
    It would be great if someone can give me a feedback!

    Hi Mike,
    The BlanketAgreement.exe is a reference to the executable that will be created when you compile the solution you created in Part II - Part III. I think there is a mistake in the tutorial because it asks you to name the project 'Blanket' which means that by default the executable will be called Blanket.exe and not BlanketAgreement.exe. The tutorial also misses the step asking you to compile the Blanket project before you go on to create an installer. You should compile your Blanket project in Release mode before creating an installer. By compiling the project you'll get a Blanket.exe file in the bin folder of your Blanket project which you then need to add to the installer per the instructions.
    SAP do offer development courses in some areas and there is training material here on the SDN and on the SAP partner portal (and maybe the customer portal as well). Try searching this forum for 'training' or 'tutorial' and you should get a few links. There's also a development certification.
    Personally I'd recommend you give yourself a little project to work on and just get stuck in
    Kind Regards,
    Owen

  • Use a Content Search Web Part to Display a Picture

    Hello -
    Is there a way to use the Content Search Web Part to display the most recently added picture to a specified application?
    Please let me know if you need additional information to answer this question.
    Thanks,
    Jordan

    Hello Jordan,
    I believe you could do this :
    filetype:jpg OR filetype:png OR  (and so on for all
    images types)
    AND path:"http://yoursite/youlibrary"
    Regards
    Samuel
    Sharepointerie.com

Maybe you are looking for

  • Coding In PI to detect and alert R/3 downtime

    Hi Experts ,                                  Mine is a FTP XI R/3 scenerio. Data from FTP enter XI [ FTP adapters]  , and after logicical manipulatations enter R/3 as idocs using IDOC adapters . The problem is sometime the production is needed to be

  • How many methods copies will create when i create multiple objects

    Hi I have big doubt in java. See the following Program class A{ public int i; public static int j; public void methodOne(){ Sytem.out.println("Welcome"); public static void methodTwo(){ System.out.println("Welcome methodOne"); class B{ public static

  • Price and condition in Contract management SRM 7 version

    Dear supporters, We work SRM server 550, We use the contract management.  In SRM 5 SEREVER 550 if you use condition in contract item the price donu2019t present in the lines items and the system present the words "see conditions". We consider the upg

  • Windows XP will not update to latest version of iTunes, any ideas

    iPhone will not connect to PC (Windows XP) because PC requires 11.1 or later.  When I try and install the latest download it states "the feature is on a network resource that is unavailable, enter an alternate path to "iTunes.msi".  What does this me

  • Learning Java On Apple Mac OS 10

    Hi I am just in the early stages of learning Java, using an Apple Mac G4 running OS 10.2.3 Does anyone know the best software to download to practice, Type /compile and run my programmes on without having to use the Unix Terminal interface... The App