📄 testfx.java~32~
字号:
package com.test;
public class TestFX {
private Object[] objs;
private int index = 0;
private int defaultCap = 10;
public TestFX() {
objs = new Object[defaultCap];
}
public static void main(String[] args) {
TestFX testfx = new TestFX();
}
public void add(Object o){
objs[index] = o;
index++;
if(index==defaultCap){
exCap();
}
}
public void exCap(){
Object[] newobjs = new Object[defaultCap*2];
defaultCap = defaultCap*2;
for (int i = 0; i < objs.length; i++) {
newobjs[i] = objs[i];
}
objs = newobjs;
}
public Object get(int myIndex){
if(myIndex>index-1){
try {
throw new Exception("没有相应的元素");
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}else{
return objs[myIndex];
}
}
public void removeAll(){
for (int i = 0; i < objs.length; i++) {
objs[i] = null;
}
index = 0;
}
public void remove(int k){
Object[] newobjs = new Object[defaultCap];
for (int i = 0; i < k; i++) {
newobjs[i] = objs[i];
}
for (int i = k+1; i <objs.length; i++) {
newobjs[i-1] = objs[i];
}
objs = newobjs;
index--;
}
public int getSize(){
return index;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -