常用数据结构对应
php中常用的数据结构是Array数组,相对的在java开发中常用的数据结构是ArrayList和HashMap,它们可以看成是array的拆分,一种简单的对应关系为
PHP | JAVA |
---|---|
Array: array(1,2,3) | ArrayListl |
Array: array(“name” => “jack”,“age” => 20) | HashMap:Map map = new HashMap() |
java代码示例:
package wisdom;import java.util.HashMap;
import java.util.Map;public class HashMapTest {public static void main(String[] args) {Map<String,String> map = new HashMap<>();map.put("name","jack");map.put("age","20");map.put("birth","2020-09-19");System.out.println(map.get("name"));String[] city = new String[10];city[0] = "南京";System.out.println(city[0]);System.out.println(map.put("name","lucy"));System.out.println(map.get("name"));map.remove("name");System.out.println(map.get("name"));System.out.println("containskey:" + map.containsKey("age"));}
}
编译运行结果: