1.序列化:
Externallizable 序列化是对指定属性
Serializable 序列化整个对象
2.进程和线程
进程,运行的应用程序
操作系统都支持多进程
线程即进程中负责程序执行的控制单元
线程状态:新建new,就绪runnable,运行
running,阻塞Blocked,死亡Dead
多线程:基于多个执行流,在一个进程中多个线
程并发执行不同的任务,可以最大限度减低CP
Java程序必备线程:
主线程:负责main
垃圾回收栈进程
3.IO流实现读文本文件
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Test {
public static void main(String[] args) {
try (FileReader fileReader = new FileReader("Test.txt");
BufferedReader reader = new BufferedReader(fileReader);//处理流,缓冲流,字符流
) {
List<Student> lst = new ArrayList<>();
while (reader.ready())
{
String s = reader.readLine();
//System.out.println(s);
String[] subs = s.split("-");
System.out.println(Arrays.toString(subs));
Student stu = new Student(subs[0],subs[1],subs[2]);
lst.add(stu);
}
//关闭流:先开后关
reader.close();
fileReader.close();
//遍历集合
lst.stream().forEach(System.out::println);
//查找
Student student = lst.stream().min((s, s1) -> {
return s.getClazz().compareTo(s1.getClazz());
}).get();
System.out.println(student);
//查找方法二
//Object[] objects = lst.stream().sorted((stu, stu1) -> {
//return stu.getClazz().compareTo(stu1.getClazz());
//}).toArray();
//System.out.println(objects[0]);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public class Student {
private String name;
private String clazz;
private String type;
public Student() {
}
public Student(String name, String clazz, String type) {
this.name = name;
this.clazz = clazz;
this.type = type;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getClazz() {
return clazz;
}
public void setClazz(String clazz) {
this.clazz = clazz;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
@Override
public String toString() {
return "Student{" +
"name='" + name + '\'' +
", clazz='" + clazz + '\'' +
", type='" + type + '\'' +
'}';
}
}
运行截图