How to get Array Length in Go? - Tutorial Kart

[Pages:2]How to get Array Length in Go?

Go ? Get Array Length

To get length of an array in Go, use builtin len() function. Call len() function and pass the array as argument. The function returns an integer representing the length of the array.

The syntax to call len() to find the length of an array arr is

len(arr)

Example

In the following program, we will create an array arr of specific size, and find its length programmatically using len() function.

example.go

package main import "fmt" func main() {

arr := [5]int{1, 2, 3, 4, 5} arrLength := len(arr) fmt.Println("Length of Array is :", arrLength) }

Output

Length of Array is : 5

Conclusion

In this Golang Tutorial, we learned how to find the length of an Array in Go programming, using len() function, with the help of example program.

Golang Golang Tutorial Run Golang Program Golang If Else Golang Switch Golang For Loop Golang Comments Golang Functions Golang Array Golang Slice Golang Struct Golang Class Golang Range Golang Map Golang Goroutine Golang Channel

Golang String Operations Golang String Length Golang String Concatenation Golang Split String Golang String - Get Index of Substr Golang String to Uppercase Golang String to Lowercase Golang Convert String to Integer

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download