- 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
IntBuffer duplicate() method in Java
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
import 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); buffer1.put(5); buffer1.rewind(); System.out.println("The Original IntBuffer is: " + Arrays.toString(buffer1.array())); IntBuffer buffer2 = buffer1.duplicate(); System.out.print("The Duplicate IntBuffer is: " + Arrays.toString(buffer2.array())); } catch (IllegalArgumentException e) { System.out.println("Error!!! IllegalArgumentException"); } catch (ReadOnlyBufferException e){ System.out.println("Error!!! ReadOnlyBufferException"); } } }
The output of the above program is as follows −
Output
The Original IntBuffer is: [8, 1, 3, 7, 5] The Duplicate IntBuffer is: [8, 1, 3, 7, 5]
- Related Articles
- IntBuffer compareTo() method in Java
- IntBuffer array() method in Java
- IntBuffer compact() method in Java
- IntBuffer hasArray() method in Java
- IntBuffer allocate() method in Java
- IntBuffer slice() method in Java
- IntBuffer wrap() method in Java
- IntBuffer get() method in Java
- IntBuffer put() method in Java
- IntBuffer arrayOffset() method in Java
- IntBuffer equals() method in Java
- IntBuffer as ReadOnlyBuffer() method in Java
- FloatBuffer duplicate() method in Java
- DoubleBuffer duplicate() method in Java
- ShortBuffer duplicate() method in Java

Advertisements