集合高级应用
Map--keySet()
Map--Entry:键值对的映射关系对象
static interface Entry<K,V>();
Map--entrySet()
getKey()
getValue()
Map嵌套
public static void main(String[] args){ HashMap<String, String> javase = new HashMap<String, String>(); HashMap<String, String> javaee = new HashMap<String, String>();
javase.put(); javase.put(); javaee.put(); javaee.put(); HashMap<String, HashMap<String, String>> banjis = new HashMap<String, HashMap<String, String>>();
}
//集合遍历:KeySet public static void keySet(HashMap<String, HashMap<String, String>> banjis){
Set<String> banjiNameSet = banjis.keySet(); Iterator<String> banjiNameIt = banjiNameSet.iterator(); while(banjiNameIt.hasNext()){ String banjiNameKey = banjiNameIt.next(); HashMap<String, String> banji = banjis.get(banjiNameKey); Set<String> studentsName = banji.KeySet(); Iterator<String> stuNameIt = studentsName.iterator(); while(StuNameIt.hasNext()){ String stuName = stuNameIt.next(); String name = banji.get(stuName); } }
} //EntrySet()键值对关系对象 public void entrySet(HashMap<String, HashMap<String, String>> banjis){
Set<Map.Entry<String, HashMap<String, String>>> banjiNameSet = banjis.entrySet(); Iterator<Map.Entry<String,HashMap<String,String>>> banjiNameIt = banjiNameSet.iterator(); while(banjiNameIt.hasNext()){ Map.Entry<String,HashMap<String,String>> banjiEntry = banjiNameIt.next(); String banjiNameKey = banjiEntry.getKey(); HashMap<String, String> StuEntry = banjiEntry.getValue(); ......
}
静态导入(应用不是太广)
- 简化代码量
import static java.lang.System.out //导入的最末尾必须是一个静态成员
可变参数(argument)
前提: 方法的参数类型确定
,个数任意
public static int getSum(int...argName){
//[I@4342324
System.out.println(argName)
}
**本质:**传入的参数都是一个数组
注意事项: 一个方法只能有一个可变参数
可变参只能放在方法的最后一个位置