Open In App

ring.Len() Function in Golang With Examples

Last Updated : 05 May, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads