In this tutorial, we are going to learn about the copy method set data structure. Let's see it in detail.The method copy is used to get a shallow copy of a set.Let's see different examples to under normal and shallow copy of a set.Normal CopyFollow the below steps and understand the output.Initialize a set.Assign the set to another variable with the assignment operator.Now, add one more element to the copied set.Print both sets.You won't find any difference between. The assignment operator returns the set reference. both sets are pointing to the same object in the memory. So, whatever changes made ... Read More
Lambda expression is an anonymous method (method without a name) that has used to provide the inline implementation of a method defined by the functional interface while a method reference is similar to a lambda expression that refers a method without executing it. The arrow (->) operator can be used to connect the argument and functionality in a lambda expression while the (::) operator separates the method name from the name of an object or class in a method reference.Syntax for Lambda Expression([comma seperated argument-list]) -> {body}Syntax for Method Reference :: Exampleimport java.util.*; public class LambdaMethodReferenceTest { public static void main(String args[]) { ... Read More
In this tutorial, we are going to learn about the clear method of set data structure. Let's see details about the clear method.The method clear is used to clear all the data from the set data structure. All elements from set will clear. And we will leave with an empty set.Follow the below steps to see clear method in action.Initialize a set.User the clear method and clear the set.Print the set and you will see an empty one.Example Live Demo# initialzing a set number_set = {1, 2, 3, 4, 5} # clearing the set number_set.clear() # printing the set print(number_set)OutputIf you ... Read More
In this tutorial, we are going to learn about the add method of set data structure. Let's dive into the tutorial.Set data structure stores unique elements in it. The add method of set data structure takes an element and adds it to the set.Follow the below steps to add a new element to the set.Initialize a set.Add a new element to the set using the add method.Print the updated set.Example Live Demo# initialzing the set numbers_set = {1, 2, 3, 4, 4, 5} # adding an element to the set numbers_set.add(6) # printing the updated set print(numbers_set)OutputIf you run the above ... Read More
In this tutorial, we are going to learn how to send SMS in Python. We will be using Twilio for sending SMS.First of all, go the Twilio and create an account. You will get free trial account. And finish settings.We have to install a module called twilio to work with Twilio client. Install it with the following command.pip install twilioNow, go to the Twilio Documentation on how to send SMS using Twilio client. Or follow the steps to send the SMS.Import the twilio Client from twilio.rest.Get and store the account_sid and auth_token from the your Twilio account.Make instance of the ... Read More
In this tutorial, we are going to learn about the self in Python. You must be familiar with it if you are working with Python. We will see some interesting things about.Note − self is not a keyword in Python.Let's start with the most common usage of self in Python.We'll use self in classes to represent the instance of an object. We can create multiple of a class and each instance will have different values. And self helps us to get those property values within the class instance. Let's see ane example.Example# class class Laptop: # init method ... Read More
A method reference is a new feature in Java 8, which is related to Lambda Expression. It can allow us to reference constructors or methods without executing them. The method references and lambda expressions are similar in that they both require a target type that consists of a compatible functional interface.SyntaxClass :: instanceMethodNameExampleimport java.util.*; import java.util.function.*; public class ArbitraryObjectMethodRefTest { public static void main(String[] args) { List persons = new ArrayList(); persons.add(new Person("Raja", 30)); persons.add(new Person("Jai", 25)); persons.add(new Person("Adithya", 20)); persons.add(new Person("Surya", 35)); persons.add(new ... Read More
The lambda expressions are inline code that implements a functional interface without creating an anonymous class. In Java 8, forEach statement can be used along with lambda expression that reduces the looping through a Map to a single statement and also iterates over the elements of a list. The forEach() method defined in an Iterable interface and accepts lambda expression as a parameter.Example ( List using Lambda Expression)import java.util.*; public class ListIterateLambdaTest { public static void main(String[] argv) { List countryNames = new ArrayList(); countryNames.add("India"); countryNames.add("England"); countryNames.add("Australia"); ... Read More
In Java 8, we have the ability to convert an object to another type using a map() method of Stream object with a lambda expression. The map() method is an intermediate operation in a stream object, so we need a terminal method to complete the stream.SyntaxStream map(Function
Type Inference states that the data type of any expression. For instance, a method return type or argument type can be understood automatically by the compiler. Types in the argument list can be omitted since java already know the types of the expected parameters for the single abstract method of functional interface.Syntax(var1, var2 …) -> { method body }In the below example, we can sort a String[] array by its last character.Exampleimport java.util.Arrays; public class TypeInferencingLambdaTest { public static void main(String[] args) { String[] names = {"Raja", "Jai", "Adithya", "Surya", "Chaitanya", "Ravi", "Krishna"}; Arrays.sort(names, (s1, ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP