java and python equivalent of php's foreach($array as $key => $value)

前端 未结 8 1043
抹茶落季
抹茶落季 2020-12-20 11:56

In php, one can handle a list of state names and their abbreviations with an associative array like this:



        
8条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-20 12:44

    Another way of doing it in Java. Although a better way has already been posted, this one's syntactically closer to your php code.

    for (String x:stateDict.keySet()){
            System.out.printf("The abbreviation for %s is %s\n",x,stateDict.get(x));
        }
    

提交回复
热议问题