源代码:
public class Notebook {
private ArrayList<String> notes = new ArrayList<String>();
public void add(String a) {
notes.add(a);
}
public void add(String a,int location) {
notes.add(location,a);
//插入一条信息到指定下标a
}
public int getsize() {
return notes.size();
//输入了多少条备忘录语句
}
public String getnote(int index) {
return notes.get(index);
}
public void removenote(int index) {
notes.remove(index);
}
public String[] list() {
String[] b = new String[notes.size()];
// for (int i = 0; i < notes.size(); i++) {
// b[i] = notes.get(i);
// }
notes.toArray(b);
return b;
}
public static void main(String[] args) {
// TODO 自动生成的方法存根
Notebook c = new Notebook();
c.add("今天吃什么?");
c.add("今天天气怎么样?");
c.add("今天你快乐吗?", 1);
System.out.println(c.getsize());
System.out.println(c.getnote(1));
c.removenote(1);
String[] b = c.list();
for(String a:b) {
System.out.println(a);
}
}
}
结果示例:
吾独矣
终极愿望世界和平