Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

ring.Len() Function in Golang With Examples

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

ring.Len() function in Golang computes the number of components(elements) in ring(a circular list) r. It executes in time corresponding to the number of components(elements).

Syntax:

func (r *Ring) Len() int

It returns Integer.

Example 1:




// Golang program to illustrate
// the ring.Len() function
package main
  
import (
    "container/ring"
    "fmt"
)
// Main function
func main() {
  
    // Creating a new ring of size 3
    r := ring.New(3)
  
    // Print out its length
    fmt.Println(r.Len())
  
}

Output:

3

Example 2:




// Golang program to illustrate
// the ring.Len() function
package main
  
import (
    "container/ring"
    "fmt"
)
// Main function
func main() {
    // Creating a new ring of size 10
    r := ring.New(10)
  
    // Print out its length
    fmt.Println(r.Len())
  
}

Output:

10
My Personal Notes arrow_drop_up
Last Updated : 05 May, 2020
Like Article
Save Article
Similar Reads