![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 9326 Articles for Object Oriented Programming
![Smita Kapse](https://www.tutorialspoint.com/assets/profiles/13597/profile/60_103706-1512718957.jpg)
148 Views
The add() method of the StringJoiner class is used in Java 8 to add a copy of the given CharSequence value as the next element of the StringJoiner value. If the new element ele is null, then the value null gets added.The syntax is as follows −public StringJoiner add(CharSequence ele)Here, the parameter ele is the element to be added, whereas, CharSequence is a readable sequence of char values.To work with the StringJoiner in Java 8, import the following package −import java.util.StringJoiner;We will first create a StringJoiner and set the delimeter −StringJoiner strJoin = new StringJoiner(", ")Use the add() method to ... Read More
![Nancy Den](https://www.tutorialspoint.com/assets/profiles/13557/profile/60_88439-1512714529.jpg)
130 Views
The hash code for a particular Instant object can be obtained using the hashCode() method in the Instant class in Java. This method requires no parameters and it returns the hash code for the Instant object.A program that demonstrates this is given as followsExample Live Demoimport java.time.*; import java.time.temporal.ChronoUnit; public class Demo { public static void main(String[] args) { Instant i = Instant.now(); System.out.println("The current instant is: " + i); int hashCode = i.hashCode(); System.out.println("The Hash Code value for the instant is: " + hashCode); } }OutputThe ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
491 Views
The addIfAbsent() method appends the element if it is not in the list. If the element is already in the list, then FALSE is returned.The syntax is as follows.public boolean addIfAbsent(E ele)Here, ele is the element to be added to this list, if it is not already in the list.To work with CopyOnWriteArrayList class, you need to import the following package.import java.util.concurrent.CopyOnWriteArrayList;The following is an example to implement CopyOnWriteArrayList class addIfAbsent() method in Java.Example 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); ... Read More
![Nishtha Thakur](https://www.tutorialspoint.com/assets/profiles/13598/profile/60_104893-1512719058.jpg)
114 Views
The peek() method of the LongStream class returns a stream with the elements of this stream, additionally performing the provided action on each element as elements are consumed from the resulting stream.The syntax is as follows −LongStream peek(LongConsumer action)Here, LongConsumer represents an operation that accepts a single long-valued argument and returns no result. The action parameter is a non-interfering action to perform on the elements as they are consumed from the stream.To use the LongStream class in Java, import the following package −import java.util.stream.LongStream;The following is an example to implement LongStream peek() method in JavaExample Live Demoimport java.util.stream.LongStream; public class Demo ... Read More
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
233 Views
The rangeClosed() method of the LongStream class in Java returns a sequential ordered LongStream from startInclusive to endExclusive by an incremental step of 1. This is inclusive of the initial element and the last element.The syntax is as follows −static LongStream rangeClosed(long startInclusive, long endExclusive)Here, startInclusive is the first value, whereas the endExclusive is the last.To use the LongStream class in Java, import the following package −import java.util.stream.LongStream;The following is an example to implement LongStream rangeClosed() method in Java −Example Live Demoimport java.util.stream.LongStream; public class Demo { public static void main(String[] args) { ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
75 Views
The set() method of the CopyOnWriteArrayList class is used to replace the element at the specified position in this list with the specified element. It returns the element that gets replaced.The syntax is as followspublic E set(int index, E ele)Here, the parameter index is the index of the element to replace and ele is the element to be stored at the specified position.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 set() method in JavaExample Live Demoimport java.util.concurrent.CopyOnWriteArrayList; public class Demo { public static void main(String[] ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
77 Views
The clear() method of the ArrayBlockingQueue class in Java is used to remove all the elements from this queue.The syntax is as followspublic void clear()To work with ArrayBlockingQueue class, you need to import the following packageimport java.util.concurrent.ArrayBlockingQueue;The following is an example to implement clear() method of Java ArrayBlockingQueue classExample 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); ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
162 Views
To generate Infinite Stream of Integers, you can use the Random class and its ints() methodRandom.ints()Here, we have used the ints() method to get the next integer.The following is an example displaying how to generate Infinite Stream of Integers with Random.ints() in JavaExampleimport java.util.stream.*; import java.util.*; public class Demo { public static void main(String[] args) { Random r = new Random(); r.ints().forEach(System.out::println); } }Output78799000099 8787879898 2872737888 . . .
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
200 Views
The max() method of the LongStream class in Java returns an OptionalLong describing the maximum element of this stream, or an empty optional if this stream is empty.The syntax is as followsOptionalLong max()Here, OptionalLong is a container object which may or may not contain a long value.To use the LongStream class in Java, import the following packageimport java.util.stream.LongStream;The following is an example to implement LongStream max() method in Java. The isPresent() method of the OptionalLong class returns true if the value is presentExample Live Demoimport java.util.*; import java.util.stream.LongStream; public class Demo { public static void main(String[] args) { ... Read More