Copy codeThe Code is as follows:
/**
* Js simulates List in java
*/
Var list = new Array ();
/**
* Add
* @ Param {Object} object
*/
Function add (object ){
List [list. length] = object;
}
/**
* Remove the elements at the specified position in the list.
* @ Param index specifies the position
* @ Return elements at this position
*/
Function removeIndex (index ){
Var object = this. list [index];
This. list. splice (index, 1 );
Return object;
}
/**
* Remove the specified element from the list.
* @ Param object specifies the element
* @ Return elements at this position
*/
Function remove (object ){
Var I = 0;
For (; I <list. length; I ++ ){
If (list [I] === object ){
Break;
}
}
If (I> = list. length ){
Return null;
} Else {
Return removeIndex (I );
}
}
/**
* Obtain the specified Element in the list.
* @ Param object specifies the element
* @ Return elements at this position
*/
Function get (index ){
Return list [index];
}
/**
* Remove all elements from the list.
*/
Function removeAll (){
List. splice (0, list. length );
}
/**
* Returns the number of elements in the list.
* @ Return number of elements
*/
Function size (){
Return this. list. length;
}
/**
* If the list does not contain elements, true is returned.
* @ Return true or false
*/
Function isEmpty (){
Return list. length = 0;
}