Searching for aword in an arraylist

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • YASIN786
    New Member
    • Feb 2007
    • 12

    #1

    Searching for aword in an arraylist

    I am developing a java program which reads all the sentences from the text file and adds them into an array list and when given a word, lists all those sentences which contain the given word. i can load the sentences into the arraylist and serach for a word but i don have an idea on how to load the whole sentence that contains the word i am searching for

    PLS HELP..
  • BigDaddyLH
    Recognized Expert Top Contributor
    • Dec 2007
    • 1216

    #2
    Originally posted by YASIN786
    I am developing a java program which reads all the sentences from the text file and adds them into an array list and when given a word, lists all those sentences which contain the given word. i can load the sentences into the arraylist and serach for a word but i don have an idea on how to load the whole sentence that contains the word i am searching for

    PLS HELP..
    What do you mean by "load" : "how to load the whole sentence"? It sounds like you know how to do everything required in the assignment.

    Comment

    • hsn
      New Member
      • Sep 2007
      • 237

      #3
      will think like this.
      you have the word in a string . str
      you have a sentence in a nother string str2
      by doing some search in the java API you can find a function that will see if the str is a sub string of str2.

      good luck

      hsn

      Comment

      • YASIN786
        New Member
        • Feb 2007
        • 12

        #4
        Originally posted by BigDaddyLH
        What do you mean by "load" : "how to load the whole sentence"? It sounds like you know how to do everything required in the assignment.
        Sorry for that. what i meant to say when i mentioned that it should load the whole sentence is this:
        when i search for a word in the arraylist of sentences. it should display the sentences which contain the word being searched for.

        thanks

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by YASIN786
          Sorry for that. what i meant to say when i mentioned that it should load the whole sentence is this:
          when i search for a word in the arraylist of sentences. it should display the sentences which contain the word being searched for.

          thanks
          Searching for a String in another String is easy:

          [code=java]
          String word= ...;
          String sentence= ...;
          boolean occurs= sentence.indexO f(word) >= 0;
          [/code]

          If you can do that once you can do it for an entire List of sentences, but is
          a 'sentence' just a line of text in a file or is a 'sentence' a linguistic sequence
          of words, syntactically correct and ending with a punctuation character? Note
          that sentences can span more than one line and more than one sentence can
          be present on one line. If that is what you mean by a 'sentence' we have to
          come up with a definition of what a 'sentence' actually is.

          kind regards,

          Jos

          Comment

          • YASIN786
            New Member
            • Feb 2007
            • 12

            #6
            hi JosAH
            thanks for the reply
            this is the defintiion of a sentence according to me:
            a 'sentence' a linguistic sequence of words, syntactically correct and ending with a punctuation character.
            the punctuation character is a full stop.
            thanks for the serach code but how do i go about using it so that the whole sentence containing the searched word is loaded in a textbox.

            thanks once again.

            Comment

            • r035198x
              MVP
              • Sep 2006
              • 13225

              #7
              Originally posted by YASIN786
              hi JosAH
              thanks for the reply
              this is the defintiion of a sentence according to me:
              a 'sentence' a linguistic sequence of words, syntactically correct and ending with a punctuation character.
              the punctuation character is a full stop.
              thanks for the serach code but how do i go about using it so that the whole sentence containing the searched word is loaded in a textbox.

              thanks once again.
              You don't use that code for loading into a textbox! The code is for searching for a string. How to "load" a string into a textbox depends on the nature of the textbox. e.g if the textbox is a JTextfield, then you simply do
              field.setText(m ySentence);
              where field is the JTextfield and mySentence is a string containing the sentence.

              Comment

              Working...