HI guys, a while ago I built an application to save strings to file https://www.daniweb.com/programming/software-development/threads/501460/application-to-save-wordsentences-to-file and I was wondering, what if I wanted to have the ability to search those strings, say I can choose a search key, like "bring" and search all the strings (and when I say strings I really mean sentences) for that key and when there is a match I display the whole sentence containing that key.
I'm looking into sorting and searching algorithms now, but they all seems to be working with ints, like, the binary search, (the binary search could be a good aid in this project). The thing is though, if I have multiple sentences, how would I sort them first?
Say I have "Sentence number 3", "Sentence number 1", "Sentence number 2", etc
Recommended Answers
Jump to PostIf the term you are searching for can be anywhere in the sentence, then sorting isn't going to relevant, and binary search won't help. If you will always be searchng for whole words, then maybe you could parse out all the words in each sentence and build some kind of …
Jump to Postrequired: ArrayList<String> found: ArrayList<Object>
You delare your method as returning a list of <Object>, but the receiving variable is a list of <String>. You can't assign Objects to Strings.
readAllLines returns a List<String> to that's how you should declare your return type and your receiving variable.
Jump to PostWell yes, you can update the GUI directly from inside the search method. However it's best practice to separate GUI from logic, and to keep methods as simple and local as possible. I was steering you towards a logic method that performs searches and returns the results, so you can …
Jump to PostYes. Create new List<String>, add all the matching sentences to it, and return it.
Jump to PostYes, that's right. (Equally you could have created an inner class to do the same thing.) When the user edits, it's the insert and removes that will mainly be called. But just keep it simple and write a tiny method to get the latest text, do the search, display the …
All 62 Replies
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.