You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
697 B

import java.util.ArrayList;
import java.util.List;
public class HistoryCommand {
private final List<String> commandHistory = new ArrayList<>();
public void addCommand(String command) {
commandHistory.add(command);
}
// 返回副本,避免外部直接修改内部列表
public List<String> getHistory() {
return new ArrayList<>(commandHistory);
}
public void printHistory() {
System.out.println("=== 命令历史 ===");
for (int i = 0; i < commandHistory.size(); i++) {
System.out.printf("%d: %s%n", i + 1, commandHistory.get(i));
}
}
public void clearHistory() {
commandHistory.clear();
}
}