Programming Articles

Page 2512 of 2547

IntStream mapToLong() method in Java

Daniol Thomas
Daniol Thomas
Updated on 30-Jul-2019 815 Views

The mapToLong() function in IntStream class returns a LongStream consisting of the results of applying the given function to the elements of this stream.The syntax is as follows.LongStream mapToLong(IntToLongFunction mapper)Here, the parameter mapper is a stateless function to apply to each element.Create an IntStream with some elements in the Stream.IntStream intStream = IntStream.of(50, 100, 150, 200);Now create a LongStream and use the mapToLong() with a condition.LongStream longStream = intStream.mapToLong(num → (long)num);The following is an example to implement IntStream mapToLong() method in Java.Exampleimport java.util.*; import java.util.stream.IntStream; import java.util.stream.LongStream; public class Demo {    public static void main(String[] args) {     ...

Read More

How to create a function in a database using JDBC API?

Vrundesha Joshi
Vrundesha Joshi
Updated on 30-Jul-2019 1K+ Views

Like procedures, you can also create function in a database and store them.SyntaxFollowing is the syntax of creating a function in a(MySQL) database:CREATE FUNCTION Function_Name(input_arguments) RETURNS output_parameter BEGIN declare variables; statements . . . . . . . . . . return data_type; ENDTo create a function in a database using JDBC API you need to:Register the driver: class using the registerDriver() method of the DriverManager class. Pass the driver class name to it, as parameter.Establish a connection: Connect ot the database using the getConnection() method of the DriverManager class. Passing ...

Read More

How to convert string to char array in C++?

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 2K+ Views

This is a C++ program to convert string to char array in C++. This can be done in multiple different waysType1AlgorithmBegin    Assign a string value to a char array variable m.    Define and string variable str    For i = 0 to sizeof(m)       Copy character by character from m to str.       Print character by character from str. EndExample#include #include using namespace std; int main() {    char m[]="Tutorialspoint";    string str;    int i;    for(i=0;i

Read More

C++ program to Check if a Given Binary Tree is an AVL Tree or Not

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 2K+ Views

AVL tree is a self-balancing Binary Search Tree where the difference between heights of left and right subtrees cannot be more than one for all nodes.This is a C++ program to check if a given Binary Tree is an AVL Tree or not.AlgorithmBegin function AVL() returns true if the given tree is AVL otherwise false.    if(root == NULL)       return 1    leftheight = height(root->left)    rightheight = height(root->right)    if(abs(leftheight-rightheight) left) && AVL(root->right))       return 1    return 0 EndExample#include using namespace std; class nod { //node declaration    public:    int data; ...

Read More

Why C++ does not have a virtual constructor?

Smita Kapse
Smita Kapse
Updated on 30-Jul-2019 4K+ Views

The virtual mechanism works only when we have a base class pointer to a derived class object.In C++, constructor cannot be virtual, because when constructor of a class is executed there is no virtual table in the memory, means no virtual pointer defined yet. So, the constructor should always be non-virtual.But virtual destructor is possible. Here is an exampleExample#include using namespace std; class b {    public:    b()    { cout

Read More

How to generate different random numbers in a loop in C++?

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 4K+ Views

Let us see how to generate different random numbers using C++. Here we are generating random numbers in range 0 to some value. (In this program the max value is 100).To perform this operation we are using the srand() function. This is in the C++ library. The function void srand(unsigned int seed) seeds the random number generator used by the function rand.The declaration of srand() is like below −void srand(unsigned int seed)It takes a parameter called seed. This is an integer value to be used as seed by the pseudo-random number generator algorithm. This function returns nothing.To get the number ...

Read More

How are virtual functions implemented in C++?

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 775 Views

Virtual functions in C++ used to create a list of base class pointers and call methods of any of the derived classes without even knowing kind of derived class object. Virtual functions are resolved late, at runtime.Here is an implementation of virtual function in C++ program −Example#include using namespace std; class B {    public:       virtual void s() { //virtual function          cout

Read More

Java Tuple setAt0() method for Unit class

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 154 Views

The setAt0() method is used to set the Unit value in JavaTuples and a copy with a new value at index 0.Let us first see what we need to work with JavaTuples. To work with the Unit class in JavaTuples, you need to import the following package −import org.javatuples.Unit;Note − Steps to download and run JavaTuples program. If you are using Eclipse IDE to run Unit Class in Java Tuples, then Right Click Project ->Properties ->Java Build Path ->Add External Jars and upload the downloaded JavaTuples jar file.The following is an example −Exampleimport org.javatuples.Unit; public class Demo {    public static void main(String[] ...

Read More

C++ Program to Implement Direct Addressing Tables

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 772 Views

This is a C++ program to implement Direct Addressing Tables. Direct Addressing Tables are used when each element has a key drawn from a universal set S = {0, 1, . . . ,n − 1} where n isn’t too large and each key is unique. It facilitates fast insertion, searching and deletion operations.Functions and pseudocodesBegin    insert():       Take the table variables word and key as argument.       T[ x.key ] = x, where x is a value of key.    delete():       Take the table variables word and key as argument.   ...

Read More

Get a value from Unit Tuple class in Java

Samual Sam
Samual Sam
Updated on 30-Jul-2019 241 Views

Use the getValueX() method to get a value from Unit Tuple class in Java at a particular index. For example, getValue0().Let us first see what we need to work with JavaTuples. To work with the Unit class in JavaTuples, you need to import the following package −import org.javatuples.Unit;Note − Steps to download and run JavaTuples program If you are using Eclipse IDE to run Unit Class in Java Tuples, then Right Click Project -> Properties -> Java Build Path -> Add External Jars and upload the downloaded JavaTuples jar file.The following is an example −Exampleimport org.javatuples.Unit; public class Demo {    public ...

Read More
Showing 25111–25120 of 25,466 articles
Advertisements