Found 34472 Articles for Programming

Program to loop on every character in string in C++

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

13K+ Views

Here in this program we will see how to iterate through each characters of a string in C++. To loop on each character, we can use loops starting from 0 to (string length – 1). For accessing the character we can either use subscript operator "[ ]" or at() function of string object.Input: A string “Hello World” Output: “Hello World”AlgorithmStep 1: Get the string Step 2: Use R before string to make it raw string Step 3: EndExample Code Live Demo#include using namespace std; main() { string my_str = "Hello World"; for(int i = 0; i

DoubleStream anyMatch() method in Java

Chandu yadav
Updated on 30-Jul-2019 22:30:25

64 Views

The anyMatch() method of the DoubleStream class returns whether any elements of this stream match the provided predicate.The syntax is as followsboolean anyMatch(DoublePredicate predicate)Here, the parameter predicate is a stateless predicate to apply to elements of this stream. The DoublePredicate here is a predicate of one double-valued argument.To use the DoubleStream class in Java, import the following packageimport java.util.stream.DoubleStream;Create a DoubleStream and add some elements to the streamDoubleStream doubleStream = DoubleStream.of(67.9, 89.9, 10.5, 95.8, 49.6);Now, check if any of the elements match the predicateboolean res = doubleStream.anyMatch(a -> a > 50);The following is an example to implement DoubleStream anyMatch() method ... Read More

The hashCode() method of CopyOnWriteArrayList method in Java

Arjun Thakur
Updated on 30-Jul-2019 22:30:25

80 Views

To get the hash code value of the list, you need to use the hashCode() method of the CopyOnWriteArrayList class.The syntax is as followspublic int hashCode()To work with CopyOnWriteArrayList class, you need to import the following packageimport java.util.concurrent.CopyOnWriteArrayList;The following is an example to implement CopyOnWriteArrayList class hashCode() method in JavaExample Live Demoimport java.util.concurrent.CopyOnWriteArrayList; public class Demo {    public static void main(String[] args) {       CopyOnWriteArrayList arrList = new CopyOnWriteArrayList();       arrList.add(30);       arrList.add(40);       arrList.add(60);       arrList.add(70);       arrList.add(90);       arrList.add(100);       arrList.add(120);   ... Read More

Parsing a comma-delimited std::string in C++

Nitya Raut
Updated on 30-Jul-2019 22:30:25

6K+ Views

In this program we will see how to parse comma-delimited string in C++. We will put a string where some texts are present, and they are delimited by comma. After executing this program, it will split those strings into a vector type object.To split them we are using the getline() function. The basic syntax of this function is like:getline (input_stream, string, delim)This function is used to read a string or a line from input stream.Input: Some strings "ABC, XYZ, Hello, World, 25, C++" Output: Separated string ABC XYZ Hello World 25 C++AlgorithmStep 1: Create stream from given string Step 2: ... Read More

ArrayBlockingQueue remainingCapacity() Method in Java

Ankith Reddy
Updated on 30-Jul-2019 22:30:25

53 Views

The remainingCapacity() method of the ArrayBlockingQueue class in Java is used to return the number of additional elements that the queue can adopt without blocking.The syntax is as followsint remainingCapacity()To work with ArrayBlockingQueue class, you need to import the following packageimport java.util.concurrent.ArrayBlockingQueue;The following is an example to implement remainingCapacity() method of Java ArrayBlockingQueue classExample Live Demoimport java.util.concurrent.ArrayBlockingQueue; public class Demo {    public static void main(String[] args) throws InterruptedException {       ArrayBlockingQueue q = new ArrayBlockingQueue(10);       q.add(120);       q.add(400);       q.add(450);       q.add(500);       System.out.println("ArrayBlockingQueue = " + ... Read More

How to concatenate multiple C++ strings on one line?

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

844 Views

Here we will see how to concatenate multiple strings in one line in C++. There are few different methods to do that. The easiest method is by using the plus (+) operator. The strings can be concatenated using +. We can place + sign between two strings to make them concatenated.Input: Some strings “str1”, “str2”, “str3” Output: Concatenated string “str1str2str3”AlgorithmStep 1: Take some strings Step 2: Concatenate them by placing + sign between them Step 3: Display the string Step 4: EndExample Code Live Demo#include using namespace std; int main() {    string str1, str2, str3;    str1 = "Hello"; ... Read More

DoubleStream.Builder build() method in Java

George John
Updated on 30-Jul-2019 22:30:25

69 Views

The build() method of the DoubleStream.Builder class builds the stream. It transitions this builder to the built state.The syntax is as followsDoubleStream build()To use the DoubleStream.Builder class in Java, import the following packageimport java.util.stream.DoubleStream;The following is an example to implement DoubleStream.Builder build() method in Java:Example Live Demoimport java.util.stream.DoubleStream; public class Demo {    public static void main(String[] args) {       DoubleStream.Builder builder = DoubleStream.builder();       builder.add(34.5);       builder.add(87.1);       builder.add(35.6);       builder.add(66.1);       builder.add(36.8);       builder.add(77.4);       builder.add(88.2);       builder.add(68.9);       builder.build().forEach(System.out::println);    } }Output34.5 87.1 35.6 66.1 36.8 77.4 88.2 68.9

How to concatenate a std::string and an int in C++?

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

2K+ Views

In this program we will see how to concatenate a string and integer type data in C++. To concatenate string and integer data, we have to convert integer to string at first. To convert it we are using stringstream. This provides some features. It takes number or string then make it string.Input: String “str” and Number 10 Output: Concatenated string “str10”AlgorithmStep 1: Take string and number Step 2: Convert number to string Step 3: Concatenate them Step 4: EndExample Code Live Demo#include #include using namespace std; string int_to_str(int x) {    stringstream ss;    ss

DoubleStream.Builder add() method in Java

Chandu yadav
Updated on 30-Jul-2019 22:30:25

71 Views

The add() method of the DoubleStream.Builder class in Java adds an element to the stream being built. The method returns this builder.The syntax is as followsdefault DoubleStream.Builder add(double ele)Here, ele is the element to be added to this stream.To use the DoubleStream.Builder class in Java, import the following packageimport java.util.stream.DoubleStream; Create DoubleStream.Builder: DoubleStream.Builder builder = DoubleStream.builder(); Now add some elements: builder.add(23.5); builder.add(33.1); builder.add(35.6); builder.add(53.1);The following is an example to implement DoubleStream.Builder add() method in JavaExample Live Demoimport java.util.stream.DoubleStream; public class Demo {    public static void main(String[] args) {       DoubleStream.Builder builder = DoubleStream.builder();       builder.add(23.5);   ... Read More

How do you reverse a string in place in C or C++?

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

482 Views

In this section we will see how to reverse a string in place. So we will not use some other memory spaces for reversing. In C++, we can use the std::string. But for C we have to use the character array. In this program we are using the character array to take the string. Then reversing it.Input: A string “This is a string” Output: The reversed string “gnirts a si sihT”Algorithmreverse_string(str)Input − The stringOutput − The reversed string.len := the length of the string i := 0 and j := (len-1) while i < j, do swap ... Read More

Advertisements