数组
参考链接:CS61B
|
---|
Python |
Java |
---|---|
lst = [1, 2, 3] for i in lst: print(i) |
int[] array = {1, 2, 3}; for (int i : array) { System.out.println(i); } |
Python |
Java |
---|---|
lst = [] lst.append("zero") lst.append("one") lst[0] = "zed" print(l[0]) print(len(l)) if "one" in lst: print("one in lst") for elem in lst: print(elem) |
List<String> lst = new ArrayList<>(); lst.add("zero"); lst.add("one"); lst.set(0, "zed"); System.out.println(lst.get(0)); System.out.println(lst.size()); if (lst.contains("one")) { System.out.println("one in lst"); } for (String elem : lst) { System.out.println(elem); } |
集合
Python |
Java |
---|---|
s = set() s.add(1) s.add(1) s.add(2) s.remove(2) print(len(s)) if 1 in s: print("1 in s") for elem in s: print(elem) |
Set<Integer> set = new HashSet<>(); set.add(1); set.add(1); set.add(2); set.remove(2); System.out.println(set.size()); if (set.contains(1)) { System.out.println("1 in set"); } for (int elem : set) { System.out.println(elem); } |