// Create a new StringVector v := container/vector.NewStringVector() // Add elements to the vector v.Push("apple") v.Push("banana") v.Push("cherry") // Print the vector for i := 0; i < v.Len(); i++ { fmt.Println(v.At(i)) }
import ( "container/vector" "fmt" ) func main() { // Create a new StringVector v := vector.New(len(names)) // Populate the vector with names names := []string{"Alice", "Bob", "Charlie", "Dave", "Eve"} for _, name := range names { v.Push(name) } // Print the vector for i := 0; i < v.Len(); i++ { fmt.Println(v.At(i)) } }This code creates a new empty vector with a length of 5, populates the vector with the names from a slice, and then prints the contents of the vector. The package library used is "container/vector".