Found 34472 Articles for Programming

The equals() method of AbstractList class in Java

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

131 Views

The equals() method of the AbstractList class is used to compare the specified object with this list for equality. The value TRUE is returned if both the lists are same i.e the same size and elements.The syntax is as followspublic boolean equals(Object ob)Here, ob is the object is to be compared for equality. To work with the AbstractList class, import the following packageimport java.util.AbstractList;The following is an example to implement equals() method of the AbstractlList class in JavaExample Live Demoimport java.util.ArrayList; import java.util.AbstractList; public class Demo {    public static void main(String[] args) {       AbstractList myList = new ... Read More

DoubleStream limit() method in Java

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

51 Views

The limit() method of the DoubleStream class returns a stream consisting of the elements of this stream, truncated to be no longer than max in length. The max is a parameter of the limit() method.The syntax is as followsDoubleStream limit(long max)Here, max is the number of elements the stream should be limited to.To use the DoubleStream class in Java, import the following packageimport java.util.stream.DoubleStream;Create a DoubleStream and add elementsDoubleStream doubleStream = DoubleStream.of(10.8, 20.7, 25.8, 35.7, 78.2, 89.7, 67.8, 86.3);Now, to display n number of elements, set it as a parameter value for limit()doubleStream.limit(5)The following is an example to implement DoubleStream ... Read More

C++ Program to Perform String Matching Using String Library

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

2K+ Views

Here we will see how the string library functions can be used to match strings in C++. Here we are using the find() operation to get the occurrences of the substring into the main string. This find() method returns the first location where the string is found. Here we are using this find() function multiple times to get all of the matches.If the item is found, this function returns the position. But if it is not found, it will return string::npos.Input: The main string “aabbabababbbaabb” and substring “abb” Output: The locations where the substrings are found. [1, 8, 13]AlgorithmString_Find(main_str, sub_str)Input ... Read More

DoubleStream mapToInt() method in Java

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

104 Views

The mapToInt() function of the DoubleStream class returns an IntStream consisting of the results of applying the given function to the elements of this stream.The syntax is as followsIntStream mapToInt(DoubleToIntFunction mapper)Here, mapper is a stateless function to apply to each element. The DoubleToIntFunction is a function that accepts a double-valued argument and produces an int-valued result.To use the DoubleStream class in Java, import the following packageimport java.util.stream.DoubleStream;The following is an example to implement DoubleStream mapToInt() method in JavaExample Live Demoimport java.util.stream.IntStream; import java.util.stream.DoubleStream; public class Demo {    public static void main(String[] args) {       DoubleStream doubleStream = DoubleStream.of(45.8, ... Read More

IntStream iterator() method in Java

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

181 Views

The iterator() method of the IntStream class in Java is used to return an iterator for the elements of this stream.The syntax is as followsPrimitiveIterator.OfInt iterator()Here, PrimitiveIterator.OfInt is an Iterator specialized for int values. To work with the IntStream class in Java, import the following packageimport java.util.stream.IntStream;Create an IntStream and add some elementsIntStream intStream = IntStream.of(15, 40, 55, 70, 95, 120);To return an iterator for the stream elementsPrimitiveIterator.OfInt primIterator = intStream.iterator();The following is an example to implement IntStream iterator() method in JavaExample Live Demoimport java.util.*; import java.util.stream.IntStream; public class Demo {    public static void main(String[] args) {       ... Read More

The listIterator() method of CopyOnWriteArrayList in Java

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

86 Views

The listIterator() method of the CopyOnWriteArrayList class in Java is used to return a list iterator over the elements in this list.The syntax is as followspublic ListIterator listIterator()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 listIterator() method in JavaExample Live Demoimport java.util.Iterator; import 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);   ... Read More

C++ Program to Implement Wagner and Fisher Algorithm for online String Matching

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

310 Views

In this section we will see how to compare two strings using Wagner and Fisher algorithm. Using this algorithm, we can find how many minimum changes are required to match those strings.This is a dynamic programming approach. Here we measure the Levenshtein distance from two strings.Input: Two strings “Support” & “Suppose” Output: Minimum number of required changes: 2AlgorithmWagnwe_Fisher(str1, str2)Input: Two strings str1 and str2Output: The minimum number of changesl1 := length of str1, and l2 = length of str2 define a matrix d of order (l1 * l2) fill first row of d with numbers from 0 to l1 – ... Read More

IntStream max() method in Java

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

778 Views

The IntStream max() method in the Java IntStream class is used to get the maximum element from the stream. It returns an OptionalInt describing the maximum element of this stream, or an empty optional if this stream is empty.The syntax is as followsOptionalInt max()Here, OptionalInt is a container object which may or may not contain an int value.Create an IntStream and add some elements in the streamIntStream intStream = IntStream.of(89, 45, 67, 12, 78, 99, 100);Now, get the maximum element from the streamOptionalInt res = intStream.max();The following is an example to implement IntStream max() method in Java. The isPresent() method ... Read More

LongStream.Builder accept() method in Java

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

71 Views

The accept() method of the LongStream.Builder class adds an element to the stream being built.The syntax is as followsvoid accept(long i)Here, i is the input.To use the LongStream.Builder class in Java, import the following packageimport java.util.stream.LongStream;Create a LongStreamLongStream.Builder builder = LongStream.builder();Add some elementsbuilder.accept(200L); builder.accept(600L); builder.accept(400L);The following is an example to implement LongStream.Builder accept() method in JavaExample Live Demoimport java.util.stream.LongStream; public class Demo {    public static void main(String[] args) {       LongStream.Builder builder = LongStream.builder();       builder.accept(200L);       builder.accept(600L);       builder.accept(400L);       builder.accept(350L);       builder.accept(900L);       builder.accept(850L); ... Read More

C/C++ Macro for string concatenation

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

4K+ Views

In this program we will see how the macros are used to concatenate two strings. We can create two or more than two strings in macro, then simply write them one after another to convert them into a concatenated string. The syntax is like below:#define STR1 "str1" #define STR2 " str2" #define STR3 STR1 STR2 //it will concatenate str1 and str2Input: Take two stringsOutput: Return concatenated string.AlgorithmStep 1:Take two strings Step 2: Use macro to concatenate the strings Step 3: EndExample Code Live Demo#include #define STR1 "Hello" #define STR2 "World" #define STR3 STR1 STR2 main() { printf("%s", STR3); ... Read More

Advertisements