Called wrap(String str, int start, int end) with start and end values equal to 0
And str as "This is a test string".
For the CharBuffer returned by this method, capacity() returns 0, instead of returning the size of the string.
As according to spec, CharBuffer created by calling wrap(String str, int start, int end) " The buffer's capacity will be str.length()"
String source = "This is a test string";
CharBuffer c = CharBuffer.wrap(source,0,0);
System.out.println("Capacity is: "+c.capacity());
results
Capacity is: 0
----------------------------------------------------------------------
String source = "This is a test string used to test wrap()";
int size = source.length();
CharBuffer c = CharBuffer.wrap(source,10,size);
System.out.println("Position :"+c.capacity()+" Expected : "+size);
results in
capacity :31 Expected: 41
according to Specs
wrap(String str,int start,int end) wraps a string into a Buffer and its capacity will be str.length()
And str as "This is a test string".
For the CharBuffer returned by this method, capacity() returns 0, instead of returning the size of the string.
As according to spec, CharBuffer created by calling wrap(String str, int start, int end) " The buffer's capacity will be str.length()"
String source = "This is a test string";
CharBuffer c = CharBuffer.wrap(source,0,0);
System.out.println("Capacity is: "+c.capacity());
results
Capacity is: 0
----------------------------------------------------------------------
String source = "This is a test string used to test wrap()";
int size = source.length();
CharBuffer c = CharBuffer.wrap(source,10,size);
System.out.println("Position :"+c.capacity()+" Expected : "+size);
results in
capacity :31 Expected: 41
according to Specs
wrap(String str,int start,int end) wraps a string into a Buffer and its capacity will be str.length()
- duplicates
-
JDK-4413135 (bf) CharBuffer.wrap(String, int, int) sets bad limit, position, capacity
-
- Closed
-