Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App
Next Article:
Buffer flip() methods in Java with Examples
Next article icon

DoubleBuffer flip() methods in Java with Examples

Last Updated : 19 Jan, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

The flip() method of java.nio.DoubleBuffer Class is used to flip this buffer. By flipping this buffer, it meant that the buffer will be trimmed to the current position and  then the position will be changed to zero. During this process, if any mark is there on the buffer, then that mark will be automatically discarded. 

Syntax:

public final DoubleBuffer flip()

Return Value: This method returns the flipped DoubleBuffer instance. 

Below are the examples to illustrate the flip() method: 

Examples 1: 

Java
// Java program to demonstrate // flip() method  import java.nio.*; import java.util.*;  public class GFG {     public static void main(String[] args)     {          // Declare and initialize         // the double array         double[] db             = { 10.56, 20.34, 30.78 };          // wrap the double array         // into DoubleBuffer         // using wrap() method         DoubleBuffer doubleBuffer             = DoubleBuffer.wrap(db);          // set position at index 1         doubleBuffer.position(1);          // print the buffer         System.out.println(             "Buffer before flip: "             + Arrays.toString(                   doubleBuffer.array())             + "\nPosition: "             + doubleBuffer.position()             + "\nLimit: "             + doubleBuffer.limit());          // Flip the Buffer         // using flip() method         doubleBuffer.flip();          // print the buffer         System.out.println(             "\nBuffer after flip: "             + Arrays.toString(                   doubleBuffer.array())             + "\nPosition: "             + doubleBuffer.position()             + "\nLimit: "             + doubleBuffer.limit());     } } 
Output:
Buffer before flip: [10.56, 20.34, 30.78] Position: 1 Limit: 3  Buffer after flip: [10.56, 20.34, 30.78] Position: 0 Limit: 1

Examples 2: 

Java
// Java program to demonstrate // flip() method  import java.nio.*; import java.util.*;  public class GFG {     public static void main(String[] args)     {          // defining and allocating DoubleBuffer         // using allocate() method         DoubleBuffer doubleBuffer             = DoubleBuffer.allocate(4);          // put double value in DoubleBuffer         // using put() method         doubleBuffer.put(20.4);         doubleBuffer.put(34.5);          // set position at index 1         doubleBuffer.position(1);          // print the buffer         System.out.println(             "Buffer before flip: "             + Arrays.toString(                   doubleBuffer.array())             + "\nPosition: "             + doubleBuffer.position()             + "\nLimit: "             + doubleBuffer.limit());          // Flip the Buffer         // using flip() method         doubleBuffer.flip();          // print the buffer         System.out.println(             "\nBuffer after flip: "             + Arrays.toString(                   doubleBuffer.array())             + "\nPosition: "             + doubleBuffer.position()             + "\nLimit: "             + doubleBuffer.limit());     } } 
Output:
Buffer before flip: [20.4, 34.5, 0.0, 0.0] Position: 1 Limit: 4  Buffer after flip: [20.4, 34.5, 0.0, 0.0] Position: 0 Limit: 1

Reference: https://docs.oracle.com/javase/9/docs/api/java/nio/DoubleBuffer.html#flip--


Next Article
Buffer flip() methods in Java with Examples

R

RohitPrasad3
Improve
Article Tags :
  • Java
  • Java-Functions
  • Java-NIO package
  • Java-DoubleBuffer
Practice Tags :
  • Java

Similar Reads

  • ByteBuffer flip() methods in Java with Examples
    The flip() method of java.nio.ByteBuffer Class is used to flip this buffer. The limit is set to the current position and then the position is set to zero. If the mark is defined then it is discarded. After a sequence of channel-read or put operations, invoke this method to prepare for a sequence of
    3 min read
  • Buffer flip() methods in Java with Examples
    The flip() method of java.nio.ByteBuffer Class is used to flip this buffer. The limit is set to the current position and then the position is set to zero. If the mark is defined then it is discarded. After a sequence of channel-read or put operations, invoke this method to prepare for a sequence of
    3 min read
  • DoubleBuffer get() methods in Java with Examples
    The get() method of java.nio.DoubleBuffer Class is used to reads the double at the given buffer’s current position, and then increments the position. Syntax: public abstract double get() Return Value: This method returns the double value at the buffer’s current position. Exception: This method throw
    3 min read
  • CharBuffer flip() methods in Java with Examples
    The flip() method of java.nio.CharBuffer Class is used to flip this buffer. The limit is set to the current position and then the position is set to zero. If the mark is defined then it is discarded. After a sequence of channel-read or put operations, invoke this method to prepare for a sequence of
    2 min read
  • DoubleBuffer slice() method in Java with Examples
    The slice() method of java.nio.DoubleBuffer Class is used to creates a new double buffer whose content is a shared subsequence of the given buffer’s content. The content of the new buffer will start at this buffer’s current position. Changes to this buffer’s content will be visible in the new buffer
    3 min read
  • DoubleBuffer mark() methods in Java with Examples
    The mark() method of java.nio.DoubleBuffer Class is used to mark the current position of this DoubleBuffer as the mark of this buffer. Syntax: public DoubleBuffer mark() Return Value: This method returns this DoubleBuffer after setting the buffer's mark at the current position. Below are the example
    2 min read
  • DoubleBuffer wrap() method in Java with Examples
    wrap(double[] array) The wrap() method of java.nio.DoubleBuffer Class is used to wraps a double array into a buffer. The new buffer will be backed by the given double array; that is, modifications to the buffer will cause the array to be modified and vice versa. The new buffer’s capacity and limit w
    4 min read
  • DoubleBuffer order() methods in Java with Examples
    The order() method of java.nio.DoubleBuffer class is used to get the ByteOrder of this DoubleBuffer instance. Syntax: public abstract ByteOrder order() Return Value: This method returns this buffer's byte order.Below are the examples to illustrate the order() method:Examples 1: Java Code // Java pro
    2 min read
  • DoubleBuffer clear() methods in Java with Examples
    The clear() method of java.nio.CharBuffer Class is used to clear this buffer. While clearing this buffer following changes are done: the position is set to zero the limit is set to the capacity the mark is discarded. Syntax: public final DoubleBuffer clear() Return Value: This method returns this Do
    2 min read
  • DoubleBuffer limit() methods in Java with Examples
    The limit() method of java.nio.DoubleBuffer Class is used to modify this DoubleBuffer's limit. This method takes the limit to be set as the parameter and sets that as the new limit of this Buffer. If the mark of this Buffer is already defined and is larger than the new specified limit, then this new
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences