Found 33676 Articles for Programming

Replace part of a string with another string in C++

Farhan Muhamed
Updated on 24-Apr-2025 10:12:24

6K+ Views

In this article, we will learn the different approaches to replace a part of a string with another string using a C/C++ program. The problem statement of this program is explained below: The input of this problem will be three strings. The task is to replace all the occurrence of the second string with the third string inside the first string. For example: // Input strings "C++ Course is free on Tutorialspoint" "C++" "Python" // Output String "Python Course is free on Tutorialspoint" Replace a Substring With Another String Here is the list of all ... Read More

Remove Trailing Zeros from string in C++

Farhan Muhamed
Updated on 23-Apr-2025 18:48:44

4K+ Views

Trailing zeros are the zero occuring at the end of a string. In this article, we will discuss different approaches to remove trailing zeros from a string. The below section explains the problem statement. The input of this problem is a non-empty string containing characters and numbers. Our task is to remove all the zero's appering after the last non-zero character in the string. For example: // Input string "012424000" // Output String "012424" Remove Trailing Zeros From String Here is the list of approaches to remove all the trailing zeros from a string ... Read More

Remove spaces from std::string in C++

Farhan Muhamed
Updated on 23-Apr-2025 18:48:16

17K+ Views

In this article, we will learn all the different approaches to remove the whitespaces from a standard string in C/C++. First of all, let's understand our problem statement. The input of this problem is a non-empty string containing multiple characters and whitespaces between those characters. Our task is to print the string by ignoring all the whitespaces into the output console. For example: // Input String "This is a string" // Output String "Thisisastring" Remove Whitespaces from a String in C++ Here is the list of approaches to remove all the whitespaces from a string using ... Read More

Raw string literal in C++

Farhan Muhamed
Updated on 27-May-2025 18:11:23

570 Views

Sometimes, in C++ when you try to print a string that containing special characters like escape sequences (), backslashes (\), or quotes(""), the output may not be as expected. To avoid this, C++ provides a feature called raw string literal. In this article, we will discuss what is raw string literal and how to use it in C++. What is Raw String Literal? A raw string literal in C++ is a type of string that preserves the formatting of the string content without changing any escape sequences such as "", "\t", or "". This is useful when you want ... Read More

Collectors minBy() method in Java 8

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

491 Views

The minBy() method of the Collectors class in Java 8 returns a Collector that produces the minimum element according to a given Comparator, described as an OptionalThe syntax is as followsstatic Collector

LongStream mapToInt() method in Java

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

988 Views

The mapToInt() method returns an IntStream consisting of the results of applying the given function to the elements of this stream.The syntax is as followsmapToInt(LongToIntFunction mapper)Here, the parameter mapper is the stateless function applied to each element.Declare LongStream and add some elementsLongStream longStream = LongStream.of(1000L, 13000L, 18000L);Now, use the IntStream and mapToInt()IntStream intStream = longStream.mapToInt(val -> (int) val);The following is an example to implement LongStream mapToInt() in JavaExample Live Demoimport java.util.*; import java.util.stream.IntStream; import java.util.stream.LongStream; public class Demo {    public static void main(String[] args) {       LongStream longStream = LongStream.of(1000L, 13000L, 18000L);       IntStream intStream = ... Read More

What is AbstractSequentialList class in Java?

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

432 Views

The AbstractSequentialList class provides an implementation of the List interface. For an unmodifiable list, implement the list iterator's hasNext, next, hasPrevious, previous and index methods. For a modifiable list the programmer should implement the list iterator's set method.The syntax is as followspublic abstract class AbstractSequentialList extends AbstractListTo work with the AbstractSequentialList class in Java, you need to import the following packageimport java.util.AbstractSequentialList;First, create an AbstractSequentialList classAbstractSequentialList absSequential = new LinkedList();Now, add elementsabsSequential.add("Accessories"); absSequential.add("Home Decor"); absSequential.add("Books"); bsSequential.add("Stationery");Let us see an example to implement the AbstractSequentialList class in JavaExample Live Demoimport java.util.LinkedList; import java.util.AbstractSequentialList; public class Demo {    public static void main(String[] ... Read More

The toString() method of Java AbstractCollection class

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

328 Views

The toString() method of the AbstractCollection class is used to return the string representation of the elements of this collection.The syntax is as followspublic String toString()To work with AbstractCollection class in Java, import the following packageimport java.util.AbstractCollection;The following is an example to implement AbstractCollection toString() method in JavaExample Live Demoimport java.util.ArrayList; import java.util.AbstractCollection; public class Demo {    public static void main(String[] args) {       AbstractCollection absCollection = new ArrayList();       absCollection.add("HDD");       absCollection.add("Earphone");       absCollection.add("Headphone");       absCollection.add("Card Reader");       absCollection.add("SSD");       absCollection.add("Pen Drive");       ... Read More

The toArray(T[] a) T method of Java AbstractCollection class

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

144 Views

The difference between toArray() and toArray(T[] arr) in Java AbstractCollection is that both the methods returns an array containing all of the elements in this collection, but the latter has some additional features i.e. the runtime type of the returned array is that of the specified array.The syntax is as followspublic T[] toArray(T[] arr)Here, arr is the array into which the elements of this collection are to be stored.To work with AbstractCollection class in Java, import the following packageimport java.util.AbstractCollection;The following is an example to implement AbstractCollection toArray() method in JavaExample Live Demoimport java.util.ArrayList; import java.util.AbstractCollection; public class Demo { ... Read More

ArrayBlockingQueue add() method in Java

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

108 Views

To add elements to the ArrayBlockingQueue class, use the add() method.The syntax is as followsboolean add(E ele)Here, ele is the element to be added to the queue. To work with ArrayBlockingQueue class, you need to import the following packageimport java.util.concurrent.ArrayBlockingQueue;The following is an example to add elements in Java ArrayBlockingQueue classExample Live Demoimport java.util.concurrent.ArrayBlockingQueue; public class Demo {    public static void main(String[] args) {       ArrayBlockingQueue q = new ArrayBlockingQueue(7);       q.add(100); q.add(250); q.add(300); q.add(450); q.add(550); q.add(600); q.add(700);       System.out.println("ArrayBlockingQueue = " + q);    } }OutputArrayBlockingQueue = [100, 250, 300, 450, 550, 600, 700]

Advertisements