Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > BOOK: Beginning Java 2, JDK 5 Edition
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning Java 2, JDK 5 Edition
This is the forum to discuss the Wrox book Ivor Horton's Beginning Java 2, JDK 5 Edition by Ivor Horton; ISBN: 9780764568749
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Java 2, JDK 5 Edition section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 27th, 2006, 10:46 AM
Registered User
Join Date: Apr 2006
Location: beijing, , China.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default about charBuf.position() and Formatter

 String[] phrases = {"Rome wasn't burned in a day.",
                                               "It's a bold mouse that sits in the cat's ear.",
                                               "An ounce of practice is worth a pound of instruction."

       // Create byte buffer to hold data to be written
       ByteBuffer buf = ByteBuffer.allocate(1024);

       System.out.printf("position = %2d Limit = %4d capacity = %4d%n",
                                                         buf.position(), buf.limit(), buf.capacity());

       // Create a view buffer
       CharBuffer charBuf = buf.asCharBuffer();
       System.out.println("Char view buffer:");
       System.out.printf("position = %2d Limit = %4d capacity = %4d%n",
                                                       charBuf.position(),charBuf.limit(),charBuf.capacit y());
       Formatter formatter = new Formatter(charBuf);

       // Write to the view buffer using a formatter
       int number = 0; // Proverb number
       for(String phrase : phrases) {
       //befor i run the follow statement charBuf.position() is 0 ,after run this sentence charBuf.position() value is 42,i want to know how the answer 42 is come,how to 42 is calculate?
           formatter.format("%nProverb%3d: %s", ++number, phrase);

in this book its file name is UsingAFormatter.java at part 10 about write file.

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Free Online SQL Formatter damaha SQL Language 1 August 14th, 2018 09:35 AM
Setting formatter to org.apache.juli.FileHandler aurelije Apache Tomcat 1 January 12th, 2011 06:54 AM
How to get the position of an element nazran Javascript How-To 3 February 2nd, 2010 06:56 AM
Position barski XSLT 5 July 11th, 2007 01:54 PM
string formatter = "{0,22} {1}"; //what it mean? fukchai2000 C# 1 January 6th, 2006 08:36 AM

All times are GMT -4. The time now is 04:42 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.