How to search like LIKE operator in sql in arraylist in java [duplicate]
Possible Duplicate:
how to search like LIKe operator in sql in hash map in java
Hi friends,
I am adding hashmap in arraylist. The hashmap values contain the company name. My requirment is that if the user types 'A' value, I have to display all the values starting with 'A' company name. If the user types '开发者_JAVA百科AB' value, I have to display all the values starting with 'AB'Company name. Can anybody tell me how to do this?
My code for adding the values:
ArrayList<HashMap<String, String>> companylist = new ArrayList<HashMap<String, String>>();
StockParser stockParser=new StockParser();
stockparsedvalue=stockParser.parseXmlArticle(stockservicevalue);
for(int i=0;i<stockparsedvalue.size();i++)
{
StockParserSet parserSet=(StockParserSet)stockparsedvalue.get(i);
mapValue=new HashMap<String, String>();
mapValue.put("companyname"+i, parserSet.getCompanyname());
companylist.add(mapValue);
}
Thanks
Iterate over list and look at each entry in the map to see if the value starts with what you are looking for. For example:
final String prefix = "AB";
for(HashMap<String,String> map : companylist){
for(Entry<String,String> e: map.entrySet()){
String companyName = e.getValue();
if(companyName.startsWith(prefix)){
System.out.println(companyName);
}
}
}
精彩评论