Found 1082 Articles for Go Programming

Golang program to calculate the symmetric difference between two slices

Akhil Sharma
Updated on 24-Jul-2023 12:21:40

271 Views

Slice is similar to an array, the only difference is that an array is a fixed sequence of elements whereas slice the array elements are dynamic. This makes the slice more efficient and faster in various applications. In the slice, the elements are passed by reference instead of values. In this article, we are going to learn about different techniques to calculate the symmetric difference between two slice using Golang programming. Algorithm Step 1 − Create a package main and declare fmt(format package) package in the program where main produces executable codes and fmt helps in formatting input and ... Read More

Golang program to shuffle the elements of an array

Akhil Sharma
Updated on 13-Feb-2023 16:14:16

753 Views

An array is a fixed sequence of elements in which the elements are placed at contiguous memory locations. We will shuffle and randomly place the elements of the array. In the first case we will use fisher-yates shuffle algorithm. Let’s see how we can execute it using different logics in the Golang code. Syntax rand.Seed(value) Rand.Seed() function is used to generate random numbers. It takes a user input as argument which is the upper limit for generating random numbers. func Now() Time The Now() function is defined in time package. this function generates the current local time. to ... Read More

Golang Program to get the first given number of items from the array

Akhil Sharma
Updated on 09-Feb-2023 15:11:13

110 Views

In this tutorial, we will write a go language program to get the first given number of items from an array. We can do this by either using the inbuilt functions in go or by using for loops. The first method is more efficient in functionality than the second one but we will discuss both these methods in this program. Method 1: Getting items from an array of integers using internal functions In this method, we will write a go language program to get the first given number of items from an array by using the append() library function. Syntax ... Read More

Golang program to compare two strings

Akhil Sharma
Updated on 13-Feb-2023 16:12:08

548 Views

In go programming language, string is one of the data-types that can be used for various application. It is a collection of characters and is also immutable. In go programming language a string can't be modified after they have been created. In this article, we are going to study different techniques to compare two given strings. Syntax bytes.Equal(s1, s2) Two slices of bytes ([]byte) are compared using the Equal() method to see if they are equal. If the two slices of bytes are equal, it produces a boolean result (true or false) reflecting that fact. strings.Compare(s1, s2) The ... Read More

Golang program to remove a subset from a slice

Akhil Sharma
Updated on 13-Feb-2023 16:11:33

296 Views

Slice is similar to an array, the only difference is that an array is a fixed sequence of elements whereas slice the array elements are dynamic. This makes the slice more efficient and faster in various applications. In slice, the elements are passed by reference instead of values. In this article, we will learn different techniques to remove a subset from slice using go language programming Syntax func append(slice, element_1, element_2…, element_N) []T The append function is used to add values to an array slice. It takes number of arguments. The first argument is the array to which we ... Read More

Golang program to sort a string

Akhil Sharma
Updated on 13-Feb-2023 16:10:08

4K+ Views

A string in Golang is a collection of characters. Since strings in Go are immutable, they cannot be modified after they have been produced. Concatenating or adding to an existing string, however, enables the creation of new strings. A built-in type in Go, the string type can be used in a variety of ways much like any other data type. In this article, we will learn different techniques to sort a string using different set of examples. Syntax func Split(str, sep string) []string Split() function is used to split a string through a provided separator. This function is present ... Read More

Golang program to rotate elements of a slice

Akhil Sharma
Updated on 13-Feb-2023 16:09:32

348 Views

A slice is a sequence of elements just like an array. An array is a fixed sequence of elements whereas a slice is a dynamic array, which means its value is not fixed and can be changed. Slices are more efficient and faster than arrays moreover; they are passed by reference instead by value. Here will learn various techniques to rotate elements of a slice using go programming language. Syntax func append(slice, element_1, element_2…, element_N) []T The append function is used to add values to an array slice. It takes number of arguments. The first argument is the array ... Read More

Golang program to check if a set is the subset of another slice

Akhil Sharma
Updated on 13-Feb-2023 16:08:32

1K+ Views

Slice is similar to the array, the only difference is that an array is a fixed sequence of elements whereas slice the array elements are dynamic. This makes slice more efficient and faster in various applications. In slice the elements are passed by reference instead of values. In this article, we are going to learn various techniques to check if a set of one slice is a subset of another slice or not using Go programming language. Algorithm Step 1 − Create a package main and declare fmt(format package) package in the program where main produces executable codes and ... Read More

Golang program to convert slice into array

Akhil Sharma
Updated on 13-Feb-2023 16:07:08

3K+ Views

A slice can also be called as a dynamic array as its value is dynamic whereas a normal array is static. This makes the slice more efficient and faster. They are passed by reference instead of value. Here we are going to learn different techniques of converting a slice into array using various examples. Syntax func append(slice, element_1, element_2…, element_N) []T The append function is used to add values to an array slice. It takes number of arguments. The first argument is the array to which we wish to add the values followed by the values to add. The ... Read More

Golang program to make string immutable

Akhil Sharma
Updated on 13-Feb-2023 16:06:07

202 Views

Strings are by default immutable in Go. A string cannot be changed once it has been created. A compile-time error will appear if the value of a string is attempted to be changed. Therefore, there is no need to add any more logic to make it immutable. Let’s see how the execution is done. Here we are going to learn different techniquest of making a string immutable using go programming. Algorithm Step 1 − Create a package main and declare fmt(format package) package in the program where main produces executable codes and fmt helps in formatting input and output. ... Read More

Advertisements