2016-06-27 02:21:09 +00:00
|
|
|
// 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.
|
2015-03-07 16:09:47 +00:00
|
|
|
|
|
|
|
package examples
|
|
|
|
|
2015-03-08 02:27:27 +00:00
|
|
|
import (
|
|
|
|
"github.com/emirpasic/gods/lists/arraylist"
|
|
|
|
"github.com/emirpasic/gods/utils"
|
|
|
|
)
|
2015-03-07 16:09:47 +00:00
|
|
|
|
2016-06-24 19:52:16 +00:00
|
|
|
// ArrayListExample to demonstrate basic usage of ArrayList
|
2015-03-07 16:09:47 +00:00
|
|
|
func ArrayListExample() {
|
|
|
|
list := arraylist.New()
|
|
|
|
list.Add("a") // ["a"]
|
2015-03-08 02:27:27 +00:00
|
|
|
list.Add("c", "b") // ["a","c","b"]
|
|
|
|
list.Sort(utils.StringComparator) // ["a","b","c"]
|
2015-03-07 16:09:47 +00:00
|
|
|
_, _ = list.Get(0) // "a",true
|
|
|
|
_, _ = list.Get(100) // nil,false
|
|
|
|
_ = list.Contains("a", "b", "c") // true
|
|
|
|
_ = list.Contains("a", "b", "c", "d") // false
|
2015-03-12 23:06:49 +00:00
|
|
|
list.Swap(0, 1) // ["b","a",c"]
|
|
|
|
list.Remove(2) // ["b","a"]
|
|
|
|
list.Remove(1) // ["b"]
|
2015-03-07 16:09:47 +00:00
|
|
|
list.Remove(0) // []
|
|
|
|
list.Remove(0) // [] (ignored)
|
|
|
|
_ = list.Empty() // true
|
|
|
|
_ = list.Size() // 0
|
|
|
|
list.Add("a") // ["a"]
|
|
|
|
list.Clear() // []
|
|
|
|
}
|