Found 7442 Articles for Java

StringJoiner toString() method in Java 8

Nancy Den
Updated on 30-Jul-2019 22:30:25

295 Views

The toString() method of the StringJoiner class in Java8 is used to return the string representation of the StringJoiner.The syntax of the toString() method is as follows:String toString()To work with the StringJoiner in Java 8, import the following package:import java.util.StringJoiner;The following is an example to implement StringJoiner toString() method in Java:Example Live Demoimport java.util.StringJoiner; public class Demo {    public static void main(String[] args) {       StringJoiner strJoin = new StringJoiner(" ");       strJoin.add("One");       strJoin.add("Two");       strJoin.add("Three");       strJoin.add("Four");       strJoin.add("Five");       System.out.println(strJoin.toString());    } }outputOne ... Read More

What is StringJoiner class in Java 8?

Nancy Den
Updated on 30-Jul-2019 22:30:25

257 Views

The StringJoiner class in Java 8 constructs a sequence of characters. This sequence is separated by a delimiter and optionally starting with a supplied prefix and ending with a supplied suffix.The following are the constructors of the StringJoiner class:StringJoiner(CharSequence delimiter): This constructor constructs a StringJoiner with no characters in it and with no prefix or suffix. It used the copy of the supplied delimiter.StringJoiner(CharSequence delimiter, CharSequence prefix, CharSequence suffix) This constructor constructs a StringJoiner with no characters in it. It uses the copies of the supplied prefix, delimiter and suffix.The syntax is as follows:public final class StringJoiner extends ObjectHere, class ... Read More

Iterate through KeyValue Tuple in Java

Nancy Den
Updated on 30-Jul-2019 22:30:25

469 Views

To iterate through the KeyValue tuple in Java, use the Iterable and loop it through using the for loop. Let us first see what we need to work with JavaTuples. To work with KeyValue class in JavaTuples, you need to import the following package:import org.javatuples.KeyValue;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 ... Read More

Create KeyValue Tuple from another collection in Java

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

87 Views

To create KeyValue tuple from another collection, use the fromCollection() method. We will be creating the tuple from List collection. Let us first see what we need to work with JavaTuples. To work with KeyValue class in JavaTuples, you need to import the following package.import org.javatuples.KeyValue;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 ... Read More

Create LabelValue Tuple from another collection in Java

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

91 Views

To create LabelValue tuple from another collection, use the fromCollection() method or the fromArray() method. Here, we will be creating LabelValue from List, therefore use the fromCollection() method.Let us first see what we need to work with JavaTuples. To work with LabelValue class in JavaTuples, you need to import the following package.import org.javatuples.LabelValue;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 ... Read More

Create Decade Tuple using with() method in Java

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

106 Views

To create a Decade Tuple in Java, you can use the with() method. Let us first see what we need to work with JavaTuples. To work with Decade class in JavaTuples, you need to import the following package.import org.javatuples.Decade;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 example to create Decade Tuple ... Read More

The listIterator() method of AbstractList class in Java

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

127 Views

The listIterator() method of the AbstractList class in Java is used to return a list iterator over the elements in this list.The syntax is as follows.public ListIterator listIterator()Here, ListIterator is an iterator for lists.To work with the AbstractList class, import the following package.import java.util.AbstractList;For ListIterator, import the following package.import java.util.ListIterator;The following is an example to implement listIterator() method of the AbstractlList class in Java.Example Live Demoimport java.util.ArrayList; import java.util.ListIterator; import java.util.AbstractList; public class Demo {    public static void main(String[] args) {       AbstractList myList = new ArrayList();       myList.add(75);       myList.add(100);       ... Read More

The listIterator() method AbstractList class in Java at a specified position

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

112 Views

The listIterator() method of the AbstractList class in Java is used to return a list iterator over the elements in this list, beginning at the specified position in the list.The syntax is as follows.public ListIterator listIterator(int index)Here, index is the index of the first element to be returned from the list iterator, whereas, ListIterator is an iterator for lists.To work with the AbstractList class, import the following package.import java.util.AbstractList;For ListIterator, import the following package.import java.util.ListIterator;The following is an example to implement listIterator() method of the AbstractlList class in Java.Example Live Demoimport java.util.ArrayList; import java.util.ListIterator; import java.util.AbstractList; public class Demo {   ... Read More

ArrayBlockingQueue iterator() method in Java

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

240 Views

The iterator() method of the ArrayBlockingQueue class returns an iterator over the elements in this queue in proper sequence.The syntax is as follows.public Iterator iterator()To work with ArrayBlockingQueue class, you need to import the following package.import java.util.concurrent.ArrayBlockingQueue;The following is an example to implement iterator() method of Java ArrayBlockingQueue class.Example Live Demoimport java.util.ArrayList; import java.util.Iterator; import 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(10);       q.add(400);       q.add(450);       q.add(500);       q.add(550); ... Read More

Collectors partitioningBy() method in Java 8

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

2K+ Views

The partioningBy() method returns a Collector that partitions the input elements according to a Predicate, and organizes them into a Map.The syntax is as follows.static Collector partitioningBy(Predicate

Advertisements