public class Demo1 { public static void main(String[] args) { //调用list集合,可以用ArrayList接受 List<Book> list=new ArrayList<>(); list.add(new Book("张三",100)); list.add(new Book("李四",400)); list.add(new Book("王五",500)); //在li4之前插入一个工人,信息为:姓名:zhao6,年龄:24,工资3300 list.add(1,new Book("zhao6",3300)); //删除wang5的信息 list.remove(3); for (int i = 0; i < list.size(); i++) { System.out.println(list.get(i)); } } }
public class Book implements Comparable { private String name; private double price; public Book(String name, double price) { this.name = name; this.price = price; } public Book() { } public String getName() { return name; } public void setName(String name) { this.name