func (iterator *Iterator) Begin() // 将迭代器重置为初始状态,然后调用Next获取第一个元素
func (iterator *Iterator) End() // 将迭代器移过最后一个元素,然后调用Prev获取最后一个元素
// 将迭代器移动到第一个元素,如果容器中有第一个元素则返回true。
// 如果First()返回true,则可以通过index()和value()检索第一个元素的索引和值。修改迭代器的状态
func (iterator *Iterator) First() bool
// 将迭代器移动到最后元素,如果容器中有第一个元素则返回true。
// 如果Last()返回true,则可以通过index()和value()检索第一个元素的索引和值。修改迭代器的状态
func (iterator *Iterator) Last() bool
func (iterator *Iterator) Next() bool
func (iterator *Iterator) Prev() bool
func (iterator *Iterator) Index() int
func (iterator *Iterator) Value() interface{}
func New(values ...interface{}) *List
func (list *List) Add(values ...interface{})
// 将集合中的每个元素传递给给定的函数,如果函数对所有元素都返回true,则返回true
func (list *List) All(f func(index int, value interface{}) bool) bool
// 将集合中的每个元素传递给给定的函数,如果函数对任何元素返回true,则返回true
func (list *List) Any(f func(index int, value interface{}) bool) bool
func (list *List) Clear()
func (list *List) Contains(values ...interface{}) bool
func (list *List) Each(f func(index int, value interface{}))
func (list *List) Empty() bool
// 将容器中的每个元素传递给给定的函数,并返回函数为true或-1的第一个元素(索引,值)
// 如果没有元素符合条件,则返回nil
func (list *List) Find(f func(index int, value interface{}) bool) (int, interface{})
func (list *List) FromJSON(data []byte) error
func (list *List) Get(index int) (interface{}, bool)
func (list *List) IndexOf(value interface{}) int
func (list *List) Insert(index int, values ...interface{})
func (list *List) Iterator() Iterator
// 为每个元素调用给定函数一次,并返回一个包含给定函数返回值的容器
func (list *List) Map(f func(index int, value interface{}) interface{}) *List
func (list *List) Remove(index int)
// 返回一个新容器,其中包含给定函数返回真值的所有元素
func (list *List) Select(f func(index int, value interface{}) bool) *List
func (list *List) Set(index int, value interface{})
func (list *List) Size() int
func (list *List) Sort(comparator utils.Comparator)
func (list *List) String() string
func (list *List) Swap(i, j int)
func (list *List) ToJSON() ([]byte, error)
func (list *List) Values() []interface{}
例子
package main
import (
"github.com/emirpasic/gods/lists/arraylist"
"github.com/emirpasic/gods/utils"
)
// ArrayListExample to demonstrate basic usage of ArrayList
func main() {
list := arraylist.New()
list.Add("a") // ["a"]
list.Add("c", "b") // ["a","c","b"]
list.Sort(utils.StringComparator) // ["a","b","c"]
_, _ = list.Get(0) // "a",true
_, _ = list.Get(100) // nil,false
_ = list.Contains("a", "b", "c") // true
_ = list.Contains("a", "b", "c", "d") // false
list.Swap(0, 1) // ["b","a",c"]
list.Remove(2) // ["b","a"]
list.Remove(1) // ["b"]
list.Remove(0) // []
list.Remove(0) // [] (ignored)
_ = list.Empty() // true
_ = list.Size() // 0
list.Add("a") // ["a"]
list.Clear() // []
}