Explain me please what does it mean [][]byte

s := [][]byte{[]byte(“foo”), []byte(“bar”), []byte(“baz”)}

is it a 2D Slice ( slice of slices)
first of all it converts foo, bar, baz into slice of bytes and after that it converts it into slice one more time?

It’s a slice of byte slices. So each element of the slice is a byte slice.

Some string manipulations operate on byte slices, doing something like this you could feed a lot of inputs to a variadic function.

and what is the difference between []byte() and []byte{}

[]byte() does convert data that can be converted into a []byte (eg. strings), while []byte{} creates an slice of bytes, with each given “argument” as an element of it.

[]byte("foobar") == []byte{102, 111, 111, 98, 97, 114}
1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.