From the source code, they are very similar. You can see the follow:
public final Buffer flip() {
limit = position;
position = 0;
mark = -1;
return this;
}
public final Buffer rewind() {
position = 0;
mark = -1;
return this;
}
So the difference is the flip
set the limit
to the position
, while rewind
not.
Consider you have allocated a buffer with 8 bytes, you have filled the buffer with 4 bytes, then the position is set to 3, just show as follow:
[ 1 1 1 1 0 0 0 0]
| |
flip limit |
rewind limit
So rewind
just used limit has set appropriately.