标签:script 容器 stat java add data ber rem remove
package notebook;
import java.util.ArrayList;
public class NoteBook {
private ArrayList<String> notes =new ArrayList<String>(); //创建容器类的对象notes
public void add(String s)
{//加入笔记
notes.add(s);
}
public void add(String s,int location)
{//加入笔记到指定位置location
notes.add(location, s);
}
public int getSize()
{//返回保存笔记的条数
return notes.size();
}
public String getNote(int index)
{//返回某条笔记的内容
return notes.get(index);
}
public void removeNote(int index)
{//删除某条笔记
notes.remove(1);
}
public String[] list()
{//列出全部笔记内容
String[] a = new String[notes.size()];
notes.toArray(a);
return a;
}
public static void main(String[] args) {
String[] a =new String [2];
a[0] = "first";
a[1] = "second";
NoteBook nb = new NoteBook();
nb.add("first");
nb.add("second");
nb.add("third,1");
System.out.println(nb.getSize());
System.out.println(nb.getNote(0));
System.out.println(nb.getNote(1));
nb.removeNote(1);
for(String s :a)
{
System.out.println(s);
}
}
}
标签:script 容器 stat java add data ber rem remove
原文地址:http://www.cnblogs.com/jzssuanfa/p/7028649.html