Patten Matching

Hi all,

I have a String array containging a huge amount of string. when i give a particular pattern for example all strings which starts with letter 'a' then i should be able to retrive all the strings from the array which starts with 'a'.

is there any better way of doing this other than iterating the whole string array

please help

[362 byte] By [zetaa] at [2007-11-27 3:25:17]
# 1

> is there any better way of doing this other than

> iterating the whole string array

>

Unless the strings in the string array have some order that will help in the search you will have to visit each string.

If, for example, the strings were alphabetically ordered then to find all the strings starting with , say, 'p' you would just do a binary search to find one of them and then scan forwards and backwards from that one to find the rest.

sabre150a at 2007-7-12 8:28:04 > top of Java-index,Java Essentials,Java Programming...
# 2
Its that the strings may not be ordred but the substring which i need to search will always be in the begning
zetaa at 2007-7-12 8:28:04 > top of Java-index,Java Essentials,Java Programming...
# 3
one more question how can i do a binary search
zetaa at 2007-7-12 8:28:04 > top of Java-index,Java Essentials,Java Programming...
# 4
> Its that the strings may not be ordred but the> substring which i need to search will always be in> the begningThe lack of order means you will have to visit each one. You could of course order them yourself.
sabre150a at 2007-7-12 8:28:04 > top of Java-index,Java Essentials,Java Programming...
# 5
> one more question how can i do a binary search http://java.sun.com/docs/books/tutorial/collections/algorithms/index.html#searching
sabre150a at 2007-7-12 8:28:04 > top of Java-index,Java Essentials,Java Programming...