Idarhillgaar
asked on
Search for a String in StringBuffer
I load a lot of values into a StringBuffer, then I want to make a search for a certain String.
#1 Should I use Vectors instead?
#2 How will I implement a search method to go through StringBuffer and return with the String I searched after.
#1 Should I use Vectors instead?
#2 How will I implement a search method to go through StringBuffer and return with the String I searched after.
You can use the StringBuffer.indexOf method for searching strings inside a stringbuffer
You can use a Matcher. e.g. ni the API docs:
http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Matcher.html
http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Matcher.html
The above method will return you the position of that string inside the stringBuffer or -1 if not found.
>> I load a lot of values into a StringBuffer
If you just load them to the stringBufer so you can search for their existence then
you will definetly better of by adding them to HashSet and checking if exists.
If you just load them to the stringBufer so you can search for their existence then
you will definetly better of by adding them to HashSet and checking if exists.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes,
I know hastables so I'm going for those. Thanks for all your inputs
--
Idar
I know hastables so I'm going for those. Thanks for all your inputs
--
Idar
:-)
A HashMap would be better
A HashMap would be better
ASKER
oops that's what I meant - trying to multitask. :)