Dinesh Remje wrote:I dont want to use a for loop...
I came to know about the comparator inteface, but can anyone let me know about how can i use it for searching.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Dinesh Remje wrote:I dont want to use for loop as the size of the arraylist can increase in future.
Also if the string which i want to search is present at last in the arraylist, then i have to traverse the whole arraylist, each time when i want to search the same string and hence i don't like for loop.
Also i have used linkedhashmap and it worked also, but sometime i want to search for the name with the help id and at that time i need to make id as the key and sometimes i want to search the id with the help of name i need to make string as the key and thats where i need to create two linked hashmap and hence i dropped it.
And hence i stick to the use of an arraylist. Can you please let me know how to use the arraylist for searching.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:Unless you can arrange elements in a particular order, you MUST search the whole List. Now there are a few options for ordering elements:
1. Sorting.
2. Creating a SortedSet or a Map from your List.
but either of those things will involve going through the entire List, even if you don't actually write the code.
Steve
Dinesh Remje wrote:I have an ArrayList in which i store stateid and statename.
Dinesh Remje wrote:I dont want to use a for loop.
Dinesh Remje wrote:Yup my list is extremely small, but at this point of time, my application is basically does a lot of searching in the arraylist, once storing the values in the arraylist is done.
Will Comparator inteface will help in searching the arraylist, by overriding the compare method.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here