数组
来源:互联网 发布:淘宝买家id是什么 编辑:程序博客网 时间:2024/06/03 19:04
public class MyArray<T> { private Object array[]; private int elements; public MyArray() { array = new Object[50]; } public MyArray(int maxSize) { array = new Object[maxSize]; } /** * * @Title: add * @Description: 添加数据 * @param value */ public void add(T value) { array[elements] = value; elements++; } /** * * @Title: display * @Description: 显示数据 */ public void display() { System.out.print("[ "); for (int i = 0; i < elements; i++) { System.out.print(array[i] + " "); } System.out.println("]"); } /** * * @Title: size * @Description: 数据中的有效数据长度 * @return */ public int size() { return elements; } /** * * @Title: search * @Description: 查找 * @param index * @return */ public Object search(int index) { if (index < 0 || index >= elements) { throw new ArrayIndexOutOfBoundsException(); } else { return array[index]; } } /** * * @Title: delete * @Description: 删除 * @param index */ public void delete(int index) { if (index < 0 || index >= elements) { throw new ArrayIndexOutOfBoundsException(); } else { for(int i=index;i<elements - 1;i++) { array[i] = array[i + 1]; } elements --; } }}
阅读全文
0 0
- 数组
- 数组
- 数组
- 数组
- 数组
- 数组
- 数组
- 数组
- 数组
- 数组
- 数组
- 数组
- 数组
- 数组
- 数组
- 数组
- 数组
- 数组
- directadmin安装
- aterisk monitor 指定录音阶段是否录回铃音
- mysql局域网配置
- GCD的一些应用知识点
- cmd 运行jar
- 数组
- 另类的java.lang.OutOfMemoryError
- QtQml应用程序的性能考虑与建议
- gitlab ci docker模式初探
- 杭电2086数学题
- 【Android】强大的SpannableStringBuilder
- linux命令(应急用)
- Android官方开发文档Training系列课程中文版:目录
- 学习一下学习一下学习一下学习一下学习一下