try expect finally执行顺序
时间: 2023-10-29 20:06:09 浏览: 99
shell中嵌套执行expect命令实例
以下是Java代码:
```java
import java.util.*;
class Employee {
private int id;
private String name;
private double salary;
public Employee(int id, String name, double salary) {
this.id = id;
this.name = name;
this.salary = salary;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public double getSalary() {
return salary;
}
public String toString() {
return "Employee{id=" + id + ", name='" + name + "', salary=" + salary + "}";
}
}
public class Main {
public static void main(String[] args) {
Map<Integer, Employee> map = new HashMap<>();
map.put(1001, new Employee(1001, "John", 50000.0));
map.put(1002, new Employee(1002, "Jane", 60000.0));
map.put(1003, new Employee(1003, "Bob", 70000.0));
// 使用 keySet() 遍历 Map
System.out.println("使用 keySet() 遍历 Map:");
Set<Integer> keySet = map.keySet();
for (int key : keySet) {
Employee emp = map.get(key);
System.out.println(key + " -> " + emp);
}
// 使用 entrySet() 遍历 Map
System.out.println("使用 entrySet() 遍历 Map:");
Set<Map.Entry<Integer, Employee>> entrySet = map.entrySet();
for (Map.Entry<Integer, Employee> entry : entrySet) {
int key = entry.getKey();
Employee emp = entry.getValue();
System.out.println(key + " -> " + emp);
}
}
}
```
输出结果:
```
使用 keySet() 遍历 Map:
1001 -> Employee{id=1001, name='John', salary=50000.0}
1002 -> Employee{id=1002, name='Jane', salary=60000.0}
1003 -> Employee{id=1003, name='Bob', salary=70000.0}
使用 entrySet() 遍历 Map:
1001 -> Employee{id=1001, name='John', salary=50000.0}
1002 -> Employee{id=1002, name='Jane', salary=60000.0}
1003 -> Employee{id=1003, name='Bob', salary=70000.0}
```
阅读全文