- Trending Categories
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 4335 Articles for Java 8
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
166 Views
A new IntBuffer can be allocated using the method allocate() in the class java.nio.IntBuffer. This method requires a single parameter i.e. the capacity of the buffer. It returns the new IntBuffer that is allocated. If the capacity provided is negative, then the IllegalArgumentException is thrown.A program that demonstrates this is given as follows −Example Live Demoimport java.nio.*; import java.util.*; public class Demo { public static void main(String[] args) { int n = 5; try { IntBuffer buffer = IntBuffer.allocate(5); buffer.put(8); buffer.put(1); ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
84 Views
It can be checked if a buffer has the backing of an accessible int array by using the method hasArray() in the class java.nio.IntBuffer. This method returns true if the buffer has the backing of an accessible int array and false otherwise.A program that demonstrates this is given as follows −Example Live Demoimport java.nio.*; import java.util.*; public class Demo { public static void main(String[] args) { int n = 5; try { IntBuffer buffer = IntBuffer.allocate(5); buffer.put(8); buffer.put(1); ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
94 Views
The buffer can be compacted using the compact() method in the class java.nio.IntBuffer. This method does not require a parameter and it returns the new compacted IntBuffer with the same content as the original buffer. If the buffer is read-only, then the ReadOnlyBufferException is thrown.A program that demonstrates this is given as follows −Example Live Demoimport java.nio.*; import java.util.*; public class Demo { public static void main(String[] args) { int n = 5; try { IntBuffer buffer = IntBuffer.allocate(n); buffer.put(3); buffer.put(7); ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
81 Views
An int array for the buffer can be obtained using the method array() in the class java.nio.IntBuffer. If the returned array is modified, then the contents of the buffer are also similarly modified and vice versa. If the buffer is read-only, then the ReadOnlyBufferException is thrown.A program that demonstrates this is given as follows −Example Live Demoimport java.nio.*; import java.util.*; public class Demo { public static void main(String[] args) { int n = 5; try { IntBuffer buffer = IntBuffer.allocate(n); buffer.put(8); buffer.put(1); ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
84 Views
A duplicate buffer of a buffer can be created using the method duplicate() in the class java.nio.IntBuffer. This duplicate buffer is identical to the original buffer. The method duplicate() returns the duplicate buffer that was created.A program that demonstrates this is given as follows −Example Live Demoimport java.nio.*; import java.util.*; public class Demo { public static void main(String[] args) { int n = 5; try { IntBuffer buffer1 = IntBuffer.allocate(n); buffer1.put(8); buffer1.put(1); buffer1.put(3); buffer1.put(7); ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
96 Views
A buffer can be compared with another buffer using the method compareTo() in the class java.nio.IntBuffer. This method returns a negative integer if the buffer is less than the given buffer, zero if the buffer is equal to the given buffer and a positive integer if the buffer is greater than the given buffer.A program that demonstrates this is given as follows −Example Live Demoimport java.nio.*; import java.util.*; public class Demo { public static void main(String[] args) { int n = 5; try { IntBuffer buffer1 = IntBuffer.allocate(n); ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
41 Views
A read-only int buffer can be created using the contents of a buffer with the method asReadOnlyBuffer() in the class java.nio.IntBuffer. The new buffer cannot have any modifications as it is a read-only buffer. However, the capacity, positions, limits etc. of the new buffer are the same as the previous buffer.A program that demonstrates this is given as follows −Example Live Demoimport java.nio.*; import java.util.*; public class Demo { public static void main(String[] args) { int n = 5; try { IntBuffer buffer = IntBuffer.allocate(5); buffer.put(8); ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
1K+ Views
Details about HashMap and WeakHashMap that help to differentiate them are given as follows −HashMap in JavaA HashMap has key-value pairs i.e. keys that are associated with the values and the keys are in arbitrary order. A HashMap object that is specified as a key is not eligible for garbage collection. This means that the HashMap has dominance over the garbage collector.A program that demonstrates this is given as follows −Example Live Demoimport java.util.*; class A { public String toString() { return "A "; } public void finalize() { System.out.println("Finalize method"); ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
335 Views
Details about TreeMap, HashMap and LinkedHashMap that help to differentiate them are given as follows −TreeMap in JavaA TreeMap in Java is implemented using a Red-Black trees. It has key-value pairs i.e. keys that are associated with the values and the keys are ordered. A TreeMap can only have unique elements and cannot have a null key but have null elements.A program that demonstrates this is given as follows −Example Live Demoimport java.util.*; import java.lang.*; import java.io.*; public class Demo { public static void main (String[] args) { TreeMap tMap = new TreeMap(); int[] ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
54 Views
A thread safe version of the set is the CopyOnWriteArraySet in Java. This set uses an CopyOnWriteArrayList internally for the set operations. The CopyOnWriteArraySet was introduced by the JDK 1.5.A program that demonstrates this is given as follows −Example Live Demoimport java.util.concurrent.*; public class Demo extends Thread { public static void main(String[] args) { CopyOnWriteArraySet cowArraySet = new CopyOnWriteArraySet(); cowArraySet.add("Amy"); cowArraySet.add("John"); cowArraySet.add("Bob"); cowArraySet.add("Clara"); cowArraySet.add("Peter"); System.out.println(cowArraySet); } }The output of the above program is as follows −Output[Amy, John, Bob, ... Read More