mirror of https://github.com/emirpasic/gods
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
1.1 KiB
Go
32 lines
1.1 KiB
Go
8 years ago
|
// Copyright (c) 2015, Emir Pasic. All rights reserved.
|
||
|
// Use of this source code is governed by a BSD-style
|
||
|
// license that can be found in the LICENSE file.
|
||
10 years ago
|
|
||
6 years ago
|
package main
|
||
10 years ago
|
|
||
10 years ago
|
import (
|
||
|
"github.com/emirpasic/gods/lists/arraylist"
|
||
|
"github.com/emirpasic/gods/utils"
|
||
|
)
|
||
10 years ago
|
|
||
8 years ago
|
// ArrayListExample to demonstrate basic usage of ArrayList
|
||
6 years ago
|
func main() {
|
||
10 years ago
|
list := arraylist.New()
|
||
|
list.Add("a") // ["a"]
|
||
10 years ago
|
list.Add("c", "b") // ["a","c","b"]
|
||
|
list.Sort(utils.StringComparator) // ["a","b","c"]
|
||
10 years ago
|
_, _ = list.Get(0) // "a",true
|
||
|
_, _ = list.Get(100) // nil,false
|
||
|
_ = list.Contains("a", "b", "c") // true
|
||
|
_ = list.Contains("a", "b", "c", "d") // false
|
||
10 years ago
|
list.Swap(0, 1) // ["b","a",c"]
|
||
|
list.Remove(2) // ["b","a"]
|
||
|
list.Remove(1) // ["b"]
|
||
10 years ago
|
list.Remove(0) // []
|
||
|
list.Remove(0) // [] (ignored)
|
||
|
_ = list.Empty() // true
|
||
|
_ = list.Size() // 0
|
||
|
list.Add("a") // ["a"]
|
||
|
list.Clear() // []
|
||
|
}
|