gitee.com/quant1x/gox@v1.21.2/util/examples/arraylist/arraylist.go (about)

     1  // Copyright (c) 2015, Emir Pasic. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  import (
     8  	"gitee.com/quant1x/gox/util/arraylist"
     9  	"gitee.com/quant1x/gox/util/internal"
    10  )
    11  
    12  // ArrayListExample to demonstrate basic usage of ArrayList
    13  func main() {
    14  	list := arraylist.New()
    15  	list.Add("a")                         // ["a"]
    16  	list.Add("c", "b")                    // ["a","c","b"]
    17  	list.Sort(internal.StringComparator)  // ["a","b","c"]
    18  	_, _ = list.Get(0)                    // "a",true
    19  	_, _ = list.Get(100)                  // nil,false
    20  	_ = list.Contains("a", "b", "c")      // true
    21  	_ = list.Contains("a", "b", "c", "d") // false
    22  	list.Swap(0, 1)                       // ["b","a",c"]
    23  	list.Remove(2)                        // ["b","a"]
    24  	list.Remove(1)                        // ["b"]
    25  	list.Remove(0)                        // []
    26  	list.Remove(0)                        // [] (ignored)
    27  	_ = list.Empty()                      // true
    28  	_ = list.Size()                       // 0
    29  	list.Add("a")                         // ["a"]
    30  	list.Clear()                          // []
    31  }