Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   






Repeat() FUNCTION


To repeat a String a few number of times, Go provides us with a Function called 'Repeat()' that repeats a string a few number of times.


Note : Function is a topic that will be discussed in a separate tutorial. For now, you can consider, a Function is something that is dedicated to do some specific work. Just like the work of Repeat() Function is to repeat a string a few times.

Let us see the below example.


Example :



package main
import "fmt"
import "strings"
    
func main() {   
           
    x := "Hello"
    y := strings.Repeat(x,3)
            
    fmt.Println(y)
}


Output :



 HelloHelloHello

So, if you see the output. The statement,


y := strings.Repeat(x,3)

Repeats the String 'Hello' three times.


Now, to use the Repeat() Function, you need to import 'strings'.


import "strings"

As the Function Repeat() is defined in 'strings'.


Then you use 'strings' to invoke the Repeat() Function, passing the actual string to be repeated (i.e. 'x := "Hello"') and number of times the string has to be repeated(i.e. '3').


y := strings.Repeat(x,3)

java_Collections