Problem Description
I have list of strings, which contains 8000 items. Items which contains list are described below.
List
stringList = new List (8000);
stringList.add("this is first string.");
stringList.add("text which I want to search.");
stringList.add("separated string items.");
....
So you can see that every item in my list is a sentence which have more then three words.
Question.
User from outside can search through the list in the following way. For example user want to search word "first" the search algorithm must work in this way.
Search algorithm must run over the list and compare word "first" with all words in the sentence and if any word in the sentence starts with "first" it must return that sentence ". So in order to realize this algorithm I write following code, you can see code below.
Algorithm which I implement works very slow, So I want to know if there is faster algorithm or how I can made my algorithm faster ?
Code Example
Iterator
stringListIter = stringList .iterator();
while (stringListIter.hasNext()) {
String currItem = stringListIter.next();
String[] separatedStr = currItem.split(" ");
for(int i=0; iif(separatedStr[i].startsWith(textToFind))
retList.add(currItem);
}
.
stackoverflow.comm
No comments:
Post a Comment