Debian Codegraph @

examples/arraylist/arraylist.go

raw symbols SCIP
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 "cmp"
9
10 "github.com/emirpasic/gods/v2/lists/arraylist"
11 )
12
13 // ArrayListExample to demonstrate basic usage of ArrayList
14 func main() {
15 list := arraylist.New[string]()
16 list.Add("a") // ["a"]
17 list.Add("c", "b") // ["a","c","b"]
18 list.Sort(cmp.Compare[string]) // ["a","b","c"]
19 _, _ = list.Get(0) // "a",true
20 _, _ = list.Get(100) // nil,false
21 _ = list.Contains("a", "b", "c") // true
22 _ = list.Contains("a", "b", "c", "d") // false
23 list.Swap(0, 1) // ["b","a",c"]
24 list.Remove(2) // ["b","a"]
25 list.Remove(1) // ["b"]
26 list.Remove(0) // []
27 list.Remove(0) // [] (ignored)
28 _ = list.Empty() // true
29 _ = list.Size() // 0
30 list.Add("a") // ["a"]
31 list.Clear() // []
32 }