package com.qiku.day19;
import java.util.*;
public class Zuo01 {
public static void main(String[] args) {
Map map = new HashMap<>();
map.put("aaa","111");
map.put("bbb","111");
map.put("ccc","111");
map.put("ddd","222");
Collection values = map.values();
Iterator valueIt = values.iterator();
while (valueIt.hasNext()){
String value = valueIt.next();
System.out.println(value);
}
System.out.println("======================");
Set> entries = map.entrySet();
Iterator> entryIt = entries.iterator();
while (entryIt.hasNext()){
Map.Entry entry = entryIt.next();
String key = entry.getKey();
String value = entry.getValue();
System.out.println(key + "," + value);
}
System.out.println("=====================");
Set keys = map.keySet();
Iterator itKey = keys.iterator();
while (itKey.hasNext()){
String key = itKey.next();
String value = map.get(key);
System.out.println(key + "," + value);
}
}
}
package com.qiku.day19;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Zuo02 {
public static void main(String[] args) {
List list = new ArrayList<>();
for (int i = 1; i < 10; i++) {
list.add(i);
}
Collections.shuffle(list);
System.out.println("打乱顺序:"+list);
Integer max = Collections.max(list);
System.out.println("最大值:"+max);
Integer min = Collections.min(list);
System.out.println("最小值:"+min);
Collections.sort(list);
System.out.println("升序排列:"+list);
Collections.swap(list,3,4);
System.out.println("交换位置:"+list);
List str = new ArrayList<>();
for (int i = 0; i < 9; i++) {
str.add(1);
}
Collections.copy(str,list);
System.out.println("元素拷贝:"+str);
}
}
package com.qiku.day19;
import java.util.Arrays;
import java.util.Scanner;
public class Zuo03 {
public static void main(String[] args) {
//ArithmeticException类 - 算术异常
int a = 1;
System.out.println(a / 0);
//ArrayIndexOutOfBoundsException类 - 数组下标越界异常
int[] arr = new int[2];
arr[2] = 1;
//NullPointerException - 空指针异常
arr = null;
System.out.println(arr.length);
//ClassCastException - 类型转换异常
A b = new B();
C c = (C) b;
System.out.println(c);
//NumberFormatException - 数字格式异常
int d = Integer.parseInt("abc");
System.out.println(d);
//OutOfMemoryError - 内存溢出错误
String e = "a";
for (int i = 0; i < 100000; i++) {
e += e;
}
System.out.println(e);
}
}
class A {
}
class B extends A {
}
class C extends B {
}
package com.qiku.day19;
import java.util.Arrays;
public class Zuo04 {
public static void main(String[] args) {
String str="If you want to change your fate I think you must come to the school to learn java";
String[] strs = str.split(" ");
System.out.println(Arrays.toString(strs));
for (int i = 0; i < strs.length; i++) {
String a = strs[i];
int b = 0;
int c = str.indexOf(a);
while (c!=-1){
b++;
c=str.indexOf(a,c+a.length());
}
System.out.println(a+"="+b);
}
}
}