Found 34465 Articles for Programming

Create Octet Tuple from another collection in Java

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

74 Views

You can create Octel Tuple from another collection i.e. List or arrays. For List, use the fromCollection() method.Let us first see what we need to work with JavaTuples. To work with Octet class in JavaTuples, you need to import the following package −import org.javatuples.Octet;Note: Download JavaTuples Jar library to run JavaTuples program. If you are using Eclipse IDE, then Right Click Project -> Properties -> Java Build Path -> Add External Jars and upload the downloaded JavaTuples jar file. Refer the below guide for all the steps to run JavaTuples −Steps: How to run JavaTuples program in EclipseThe following is an ... Read More

IntStream boxed() method in Java

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

2K+ Views

The boxed() method of the IntStream class returns a Stream consisting of the elements of this stream, each boxed to an Integer.The syntax is as follows.Stream boxed()At first, create an IntStreamIntStream intStream = IntStream.range(20, 30);Now, use the boxed() method to return a Stream consisting of the elements of this stream, each boxed to an Integer.Stream s = intStream.boxed();The following is an example to implement IntStream boxed() method in Java.Example Live Demoimport java.util.*; import java.util.stream.Stream; import java.util.stream.IntStream; public class Demo {    public static void main(String[] args) {       IntStream intStream = IntStream.range(20, 30);       Stream s = ... Read More

The indexOf() method of AbstractList class in Java

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

94 Views

The indexOf() method is used to return the index of the first occurrence of the specified element in this list. If the list is empty, it returns -1.The syntax is as follows.int indexOf(Object ob)Here, the parameter ob is the element to search for.To work with the AbstractList class, import the following package.import java.util.AbstractList;The following is an example to implement indexOf() method of the AbstractlList class in Java.Example Live Demoimport java.util.ArrayList; import java.util.AbstractList; public class Demo {    public static void main(String[] args) {       AbstractList myList = new ArrayList();       myList.add(5);       myList.add(20);     ... Read More

Collectors.joining() method in Java 8

Anvi Jain
Updated on 30-Jul-2019 22:30:25

2K+ Views

The joining() method of the Collectors class in Java 8 returns a Collector that concatenates the input elements into a String, in encounter order.The syntax is as follows −public static Collector joining()Here, CharSequence is a readable sequence of char values, whereas String class represents character strings.To work with Collectors class in Java, import the following package −import java.util.stream.Collectors;The following is an example to implement Collectors.joining() method in Java 8 −Example Live Demoimport java.util.stream.Collectors; import java.util.stream.Stream; import java.util.Arrays; import java.util.List; public class Demo { public static void main(String[] args) { List list ... Read More

The subList() method of AbstractList class in Java

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

83 Views

The subList() method returns a part of this list between the specified fromIndex, inclusive, and toIndex, exclusive. Get a sublist using the method by setting the range as the two parameters.The syntax is as follows.public List subList(int fromIndex, int toIndex)Here, the parameter fromIndex is the low endpoint (inclusive) of the subList and toIndex is the high endpoint (exclusive) of the subList.To work with the AbstractList class, import the following package.import java.util.AbstractList;The following is an example to implement subList() method of the AbstractlList class in Java.Exampleimport java.util.ArrayList; import java.util.AbstractList; public class Demo {    public static void main(String[] args) {   ... Read More

IntStream toArray() method in Java

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

211 Views

The toArray() method returns an array containing the elements of this stream.Set the elements in the stream with the IntStream class of() method.IntStream stream = IntStream.of(20, 40, 60, 70, 100, 120, 140);Now, display an array with the elements of this stream using the toArray() method.int[] myArr = stream.toArray();The following is the syntax.int[] toArray()The following is an example to implement IntStream toArray() method in Java.Example Live Demoimport java.util.*; import java.util.stream.IntStream; public class Demo {    public static void main(String[] args) {       IntStream stream = IntStream.of(20, 40, 60, 70, 100, 120, 140);       int[] myArr = stream.toArray();       System.out.println(Arrays.toString(myArr));    } }Output[20, 40, 60, 70, 100, 120, 140]

Collectors averagingInt() method in Java 8

Smita Kapse
Updated on 30-Jul-2019 22:30:25

772 Views

The averagingInt() method of the Collectors class returns a Collector that produces the arithmetic mean of a int-valued function applied to the input elements.The syntax is as follows −static Collector averagingInt(ToIntFunction

Period isNegative() method in Java

Krantik Chavan
Updated on 30-Jul-2019 22:30:25

182 Views

It can be checked if the days, months and years in the Period are negative or not using the isNegative() method in the Period class in Java. This method requires no parameters. Also, it returns true if any of the days, months and years in the Period are negative and false if all of the days, months and years in the Period are positive.A program that demonstrates this is given as followsExample Live Demoimport java.time.Period; public class Demo {    public static void main(String[] args) {       String period = "P5Y9M4D";       Period p = Period.parse(period);   ... Read More

Deploying Scrapy spider on ScrapingHub

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

137 Views

Scrapy spiderScrapy spider is a class which provides the facility to follow the links of a website and extract the information from the webpages.This is the main class from which other spiders must inherit.ScrapinghubScrapinghub is an open source application to run Scrapy spiders. Scrapinghub turns web content into some useful data or information. It allows us to extract the data from webpages, even for complex webpages.We are going to use scrapinghub to deploy scrapy spiders on cloud and execute it.Steps to deploy spiders on scrapinghub −Step1 −Create one scrapy project −After installing scrapy, just run the following command in your ... Read More

IntStream mapToDouble() method in Java

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

700 Views

The mapToDouble() method returns a DoubleStream consisting of the results of applying the given function to the elements of this stream.The syntax is as follows.DoubleStream mapToDouble(IntToDoubleFunction mapper)Here, the parameter mapper is the stateless function applied to each element.Create an IntStream with some elements.IntStream intStream = IntStream.of(5, 20, 25, 45, 60, 75, 85, 90);Now, use the mapToDouble() method to return a DoubleStream.DoubleStream doubleStream = intStream.mapToDouble(val -> (double) val);The following is an example to implement IntStream mapToDouble() method in Java.Example Live Demoimport java.util.*; import java.util.stream.IntStream; import java.util.stream.DoubleStream; public class Demo {    public static void main(String[] args) {       IntStream intStream ... Read More

Advertisements