日期:2014-05-20 浏览次数:20911 次
package com.collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
public class TestMap {
/**
* @param args
*/
public static void main(String[] args) {
//Map<索引, 字符>
Map<Integer,Character> map = new HashMap<Integer,Character>();
map.put(1,'e') ;
map.put(3,'c') ;
System.out.println(isRight("1e3b0", map)) ;
}
@SuppressWarnings("rawtypes")
public static boolean isRight(String str, Map<Integer,Character> map){
Iterator<Entry<Integer, Character>> it = map.entrySet().iterator();
while(it.hasNext()){
Map.Entry m=(Entry<Integer, Character>)it.next();
Integer key = (Integer) m.getKey() ;
Character value = (Character)m.getValue() ;
int k = key ;
char v = value ;
if (! (str.charAt(k) == v ) ){
return false ;
}
}
return true ;
}
}