DIY一个arraylist集合,实现增删查改

import org.apache.jasper.tagplugins.jstl.core.ForEach;
import org.apache.tomcat.util.buf.UDecoder;


/**
 * 
 * @author 刘达
 *
 * @param
 */
public class MyArrayList {
public static void main(String[] args) {
MyArrayList a = new MyArrayList<>();
a.add(2);
a.add(3);
a.add(4);
a.add(12);
a.add(123);
a.remove(123);
}
private static int size;
private static Object[] Asize;
private static Object[] obj={};
public boolean flg=true;
private static Object[] removed;
public void Arraylist() {
if(size>0){
Asize =obj;
obj=new Object[size];
}else if (size==0){
Asize=obj;
}
}
/**

* @param s
*/
public void add(T s) {
size++;
Arraylist();
obj[size-1]=(Object)s;
for (int i = 0; i < Asize.length; i++) {
if (Asize[i]!=null) {
obj[i]=Asize[i];
}
}
}
public boolean updata(T g,T f) {
int count=0;
for (int i = 0; i < obj.length; i++) {
if (f.equals(obj[i])) {
obj[i]=g;
}else if (!f.equals(obj)) {
// System.out.println("1");
count++;
if (count==obj.length) {
System.out.println("不存在");
flg=false;
return flg;
}
}
}
return flg;
}


public void Found(T d){
int count=0;
for (int i = 0; i < obj.length; i++) {
if (d.equals(obj[i])) {
System.out.println("d的地址:"+i+"----"+"d的值为:"+obj[i]);
}else if (!d.equals(obj)) {
count++;
if (count==obj.length) {
System.out.println("不存在");
}
}
}
}
int vs;
String[] arrs;
public void remove(T re) {
int count=0;
String temp;
for (int i = 0; i < obj.length; i++) {
if (!re.equals(obj[i])) {
count++;
if (count==obj.length) {
System.out.println("不存在");
}
removed=new Object[count];
vs=i;
}
}
for (int i = 0; i < count; i++) {
removed[i]=obj[vs--];
}
}
}

你可能感兴趣的:(DIY一个arraylist集合,实现增删查改)