接口设计java
add(String note);设计
getSize();code
getNote(int index);对象
removeNote(int index);接口
list();rem
容器类get
ArrayList<String> notes = new ArrayList<String>class
容器有两个类型:import
容器的类型容器
元素的类型
package notebook; import java.util.ArrayList; public class NoteBook { private ArrayList<String> notes = new ArrayList<String>();//用来存放String的ArrayList。notes是对象 //定义泛型类 public void add(String s) { //存放入容器 notes.add(s); } public int getSize() { //获取容器的大小 return notes.size(); } public String getNode(int index) { return ""; } public boolean removeNote(int index) { return true; } public String[] list() { } public static void main(String[] args) { NoteBook nb = new NoteBook(); nb.add("first"); nb.add("second"); System.out.println(nb.getSize()); } }