In my particular use case, I would like to know how the following Java code would be implemented in Go -
class Channel {
public String name;
public Channel(){}
}
ArrayList<Channel> channels = new ArrayList<Channel>();
I've gotten started, and I think this would be the appropriate struct for Channel in Go -
struct Channel {
name string
}
I just need to know how ArrayList would work in Go
Use a slice:
var channels []Channel // an empty list
channels = append(channels, Channel{name:"some channel name"})
Also, your Channel declaration is slightly off, you need the 'type' keyword:
type Channel struct {
name string
}
Here's a complete example: http://play.golang.org/p/HnQ30wOftb
For more info, see the slices article.
There's also the go tour (tour.golang.org) and the language spec (golang.org/ref/spec, see #Slice_types, #Slices, and #Appending_and_copying_slices).
Use slices.
For details on common slice idioms see the "Slice Tricks" wiki page.
This works
//make the object Channel
type Channel struct {
name string
}
// a empty list
var channels = []*Channel {}
//and finally add this object
channels = append(channels, Channel{name:"juan carlos anez mejias"})