Package Exports
- arraylists
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (arraylists) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
ArrayList API:
下载
npm install arraylists
引用包
let ArrayList = require("arraylists");
创建一个ArrayList对象
let list = new ArrayList();
添加一个元素
list.add(item);
添加多个元素
list.add(item1,item2,item3...);
添加一个数组进集合
list.addAll(array);
删除指定元素
list.remove(item);
删除多个元素
list.removeAll(item1,item2,item3...);
清空集合元素
list.clear();
深克隆一个集合
let list2 = list.clone();
检查集合中是否包含指定元素
let bool = list.contains(item);
获取指定位置上的元素
let temp = list.get(index);
返回此列表中首次出现的指定元素的索引,或如果此列表不包含元素,则返回 -1
let index = list.indexOf(item);
判断集合是否为空
let bool = list.isEmpty();
用指定的元素替代此列表中指定位置上的元素
list.set(index,item);
遍历集合
list.forEach(e => {
console.log(e);
});
获取元素中第一个元素
list.first();
获取元素中最后一个元素
list.last();
返回元素个数
list.size();
去除重复元素
list.unique();
将集合转换为数组,返回一个数组,但不改变原集合
list.toArray();
判断两个集合中元素否相等
list.equals(list2);
返回在此 ArrayList 的元素上进行迭代的迭代器。
list.iterator();
https://www.npmjs.com/package/listiterator
关于作者:
email:admin@w3c.top
更新日志:
2017-4-11更新:
新增equals比较函数
新增unique函数去除集合中重复元素
新增toArray函数将集合转换为数组
新增addAll函数可直接添加一个数组进集合