472,992 Members | 3,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,992 software developers and data experts.

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..
Apr 25 '08 #1
6 2280
BigDaddyLH
1,216 Expert 1GB
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.
Apr 25 '08 #2
hsn
237 100+
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
Apr 26 '08 #3
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
Apr 27 '08 #4
JosAH
11,448 Expert 8TB
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:

Expand|Select|Wrap|Line Numbers
  1. String word= ...;
  2. String sentence= ...;
  3. boolean occurs= sentence.indexOf(word) >= 0;
  4.  
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
Apr 27 '08 #5
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.
Apr 27 '08 #6
r035198x
13,262 8TB
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(mySentence);
where field is the JTextfield and mySentence is a string containing the sentence.
Apr 28 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Randy | last post by:
I'm looking for an easy way to find the value member of an object in a control. I have an ArrayList of a simple class with two properties. One property is "Id" and the other is "CompName" (both...
4
by: dotNetDave | last post by:
I have created my own comparer class using IComparer for use with ArrayList.BinarySearch. My class seems to work with BinarySearch, but the problem is that my ArrayList has three items in it and it...
2
by: dotNetDave | last post by:
I have implemented custom sorting and searches on my complex objects (they contain properties and collections) using IComparer and BinarySearch. I knew they before doing a search you had to sort...
10
by: C Downey | last post by:
Hello: I have an arraylist storing some very basic objects. The object is very basic, it has 2 properties : ID, and COUNT Before I add an object to the arraylist, I want to check if an...
9
by: Paul Nations | last post by:
I've got arraylists of simple classes bound to controls. I need to search through those arraylists to set the correct SelectedItem in the control. The code looks like: Public Class...
33
by: Geoff Jones | last post by:
Hiya I have a DataTable containing thousands of records. Each record has a primary key field called "ID" and another field called "PRODUCT" I want to retrieve the rows that satisy the following...
6
by: AAJ | last post by:
Hi all I have some objects that I add to an ArrayList. Each object is from the same class and has methods etc. Each can be identified by a unique property, in this case PK e.g. PK =1 for...
4
by: MikeY | last post by:
Hi Everyone, I'm am trying to find the best method option for searching through an ArrayList and getting various items at a time. It could be 0 to 14, 15 to 25 etc,etc. I wish .GetRange(0,45)...
3
by: Paul73 | last post by:
This is driving me nuts. Someone please help me with this. I have a program that's reading a list of terms to search for. The .IndexOf works fine if the term being searched for is in the first...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.