Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Articles by Sabid Ansari
Page 6 of 15
How to Remove Duplicate Values from Slice in Golang?
In Golang, a slice is a dynamically-sized array that can store a collection of elements of the same type. Sometimes, you may need to remove duplicate values from a slice to ensure that each element in the slice is unique. In this article, we'll discuss how to remove duplicate values from a slice in Golang. Method 1: Using a Map One way to remove duplicate values from a slice in Golang is to use a map. Maps are a built-in type in Golang that allow you to store key-value pairs. We can use a map to keep track of the ...
Read MoreHow to Print Specific date-time in Golang?
Go is a programming language that is well-suited for building high-performance, concurrent applications. One of the essential features of any application is the ability to work with date and time. In this article, we will explore how to print specific date-time in Go using the time package. Using the Time Package in Go The time package in Go provides a variety of functions for working with dates, times, and durations. The time.Time type represents a specific moment in time, and we can use its methods to format dates and times according to a specific layout. To print a specific date-time ...
Read MoreGo vs Java
Go and Java are two popular programming languages used for developing different types of applications. While both languages have their unique features and advantages, there are some key differences between them that developers should consider when deciding which language to use for their projects. In this article, we'll explore the differences between Go and Java in terms of syntax, performance, concurrency, and more. Go Java Syntax Go has a simpler and more concise syntax compared to Java. Go has fewer keywords and syntax rules, making it easier for developers to read, write and maintain code. ...
Read MoreGenerate UUID in Golang
Universally Unique Identifier (UUID) is a 128-bit value that is used to uniquely identify objects or entities. UUID is widely used in computer systems for generating unique IDs for objects, documents, and data records. In Golang, we can generate UUID using the "github.com/google/uuid" package. Installing the "github.com/google/uuid" Package Before we can generate UUID in Golang, we need to install the "github.com/google/uuid" package. To install this package, run the following command in the terminal − go get github.com/google/uuid Generating UUID in Golang Once we have installed the "github.com/google/uuid" package, we can use the "uuid" package to generate UUIDs. Here's an ...
Read MoreGetting the current date and time with timestamp in local and other timezones in Golang
In Go, it's easy to work with dates and times using the time package. This package provides a set of functions and types for working with dates and times, including the ability to get the current date and time with a timestamp in local and other timezones. In this article, we'll explore how to get the current date and time with a timestamp in local and other timezones using Go. Getting the current date and time with timestamp in local timezone To get the current date and time with a timestamp in the local timezone, we can use the time.Now() ...
Read MoreSplitting a slice of bytes after the specified separator in Golang
In Golang, it is often required to split a slice of bytes after a specific separator. This can be done using the built-in function bytes.SplitAfter(). This function splits a slice of bytes into sub-slices after each occurrence of a specified separator. In this article, we will discuss how to split a slice of bytes after a specific separator in Golang. Syntax of bytes.SplitAfter() The syntax of the bytes.SplitAfter() function is − func SplitAfter(s, sep []byte) [][]byte where s is the slice of bytes to be split, and sep is the separator. Example package main import ( ...
Read MoreSearching an element of int type in slice of ints in Golang
Slices are an essential feature of Go programming language that allows you to store and manipulate an ordered collection of elements. Slices are similar to arrays, but unlike arrays, they are dynamic and can be resized. In Go, you can perform a search operation on a slice to find an element or a set of elements. This article will guide you through the process of searching for an element of int type in a slice of ints in Go. Searching an element of int type in slice of ints in Golang To search for an element of int type in ...
Read MoreReplacing all String which Matches with Regular Expression in Golang
In Golang, you can replace all the string occurrences that match a regular expression with the help of the regexp package. The regexp package in Golang provides a ReplaceAllString() function that replaces all occurrences of the matched string with a new string. Example Here's an example of how to replace all the string occurrences that match a regular expression in Golang − package main import ( "fmt" "regexp" ) func main() { str := "The quick brown fox jumps over the lazy dog" re := regexp.MustCompile("fox|dog") ...
Read MorePolymorphism Using Interfaces in Golang
Polymorphism is a powerful concept in object-oriented programming that allows you to write flexible and reusable code. In Go, you can achieve polymorphism using interfaces. An interface is a collection of method signatures that any type can implement. This means that you can write code that can work with any type that implements an interface, without knowing the underlying type. In this article, we will discuss how to achieve polymorphism using interfaces in Golang. What is Polymorphism? Polymorphism is the ability of an object to take on many forms. In object-oriented programming, polymorphism is achieved when an object can be ...
Read MoreHow to find the index of rune in the string in Golang?
Golang offers many built-in functions and packages to perform string operations. One common operation is finding the index of a particular rune in the string. In this article, we will explore how to find the index of a rune in a string in Golang. Rune in Golang is an alias for int32 and represents a Unicode code point. Each character in a string is a rune. The string package in Golang provides several functions for handling runes in a string. Let's take a look at how to find the index of a rune in a string in Golang. Using the ...
Read More