Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Go Arrays & Slices
Search
Nathan Youngman
May 25, 2015
Programming
0
120
Go Arrays & Slices
An overview of how slices and arrays work in Go.
Nathan Youngman
May 25, 2015
Tweet
Share
More Decks by Nathan Youngman
See All by Nathan Youngman
The Healthy Programmer
nathany
2
93
Go and Node.js: a comparison
nathany
1
170
Diet Hacks
nathany
2
340
Go 1.6 and HTTP/2
nathany
3
110
Upgrading Rails Redux
nathany
1
84
GopherCon recap
nathany
0
150
Go Functions
nathany
0
90
Go Types
nathany
2
120
Go Packages
nathany
2
520
Other Decks in Programming
See All in Programming
PHPで作るWebSocketサーバー ~リアクティブなアプリケーションを知るために~ / WebSocket Server in PHP - To know reactive applications
seike460
PRO
2
770
混沌とした例外処理とエラー監視に秩序をもたらす
morihirok
13
2.3k
Alba: Why, How and What's So Interesting
okuramasafumi
0
210
Оптимизируем производительность блока Казначейство
lamodatech
0
950
ecspresso, ecschedule, lambroll を PipeCDプラグインとして動かしてみた (プロトタイプ) / Running ecspresso, ecschedule, and lambroll as PipeCD Plugins (prototype)
tkikuc
2
1.8k
PHPとAPI Platformで作る本格的なWeb APIアプリケーション(入門編) / phpcon 2024 Intro to API Platform
ttskch
0
390
PicoRubyと暮らす、シェアハウスハック
ryosk7
0
220
ドメインイベント増えすぎ問題
h0r15h0
2
560
Amazon Nova Reelの可能性
hideg
0
200
.NETでOBS Studio操作してみたけど…… / Operating OBS Studio by .NET
skasweb
0
120
はてなにおけるfujiwara-wareの活用やecspressoのCI/CD構成 / Fujiwara Tech Conference 2025
cohalz
3
2.7k
オニオンアーキテクチャを使って、 Unityと.NETでコードを共有する
soi013
0
370
Featured
See All Featured
Fashionably flexible responsive web design (full day workshop)
malarkey
406
66k
Facilitating Awesome Meetings
lara
51
6.2k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
173
51k
How STYLIGHT went responsive
nonsquared
96
5.3k
Building Flexible Design Systems
yeseniaperezcruz
328
38k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
A designer walks into a library…
pauljervisheath
205
24k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Faster Mobile Websites
deanohume
305
30k
Writing Fast Ruby
sferik
628
61k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.2k
VelocityConf: Rendering Performance Case Studies
addyosmani
327
24k
Transcript
gophers := [4]string{"blue", "pink", "purple", "blue"}
Arrays are fixed-length planets := [8]string{ "Mercury", "Venus", "Earth", "Mars",
"Jupiter", "Saturn", "Uranus", "Neptune", } 0 1 2 3 4 5 6 7
Arrays are values planetBackup := planets // make way
for an interstellar bypass planets[2] = “" fmt.Println(planets) // [Mercury Venus Mars Jupiter Saturn Uranus Neptune] fmt.Println(planetBackup) // [Mercury Venus Earth Mars Jupiter Saturn Uranus Neptune]
Slicing makes a window terrestrial := planets[0:4] gasGiants := planets[4:6]
iceGiants := planets[6:8] 0 1 2 3 4 5 6 7 terrestrial gasGiants iceGiants
Half-open range planets[2:3] // [Earth] < 3 • starts at
index 2 • excludes index 3
Defaults terrestrial := planets[:4] gasGiants := planets[4:6] iceGiants := planets[6:]
allPlanets := planets[:]
Making a slice // allPlanets := planets[:] planets := []string{
"Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", }
Append to slices planets = append(planets, "Pluto") 0 1 2
3 4 5 6 7 8 9 10 11 12 13 14 15 fmt.Println(len(planets), cap(planets)) // 9 16
Append again planets = append(planets, "Eris", "Sedna") fmt.Println(len(planets), cap(planets))
// 11 16
http://blog.golang.org/go-slices-usage-and-internals https://github.com/golang/go/wiki/SliceTricks More reading