0

Am working in J2ME where I have a field to search for items which is placed inside vectors. So I was wondering how to do it..? If suppose I have a 3 items starting with letter "A" then how would I print three of them..? I saw this and tried this

System.out.println("ITEM "+LIST_FNAM.indexOf(SEARCH_ITEM));

but the result was

ITEM 0
Community
  • 1
  • 1
suja
  • 1,198
  • 2
  • 12
  • 32

2 Answers2

2

Assuming it is a Vector of Strings then you can do something like this:

for (String obj : vector) {
        if(obj.startsWith("A"))
           System.out.println(obj);
}
Juned Ahsan
  • 67,789
  • 12
  • 98
  • 136
0

Using regular expression would be a nice choice if you want to implement searching.

You can put the entered string in a Regex and match it with the vector. It will help you in future if you want to enhance the searching capabilities like not just matching the first characters and finding the matched if they are in the middle of the patterns too. Saying that java provides a wonderful Regex matching support so implementing it won't be a much big issue also.

dirtydexter
  • 1,063
  • 1
  • 10
  • 17