Speed using java.nio.ByteBuffer vs byte[]

I have a potentially huge array of bytes that will be created at runtime which my program will then need to access frequently at random locations. I'm not sure whether it is best to store the array in a traditional byte[] and simply dereference the index I need, or to create a ByteBuffer and seek then read. I've heard that ByteBuffer is 'faster', but am not sure if that would apply to this situation.

[414 byte] By [Mark_McKaya] at [2007-10-3 5:22:40]
# 1

Input/output to a ByteBuffer is potentially 'faster' than I/O via a stack of InputStreams and OutputStreams. It's certainly not faster than a byte[] array, it's much slower.

If the data is coming from a file you could look at MappedByteBuffer, which will be quicker than doing all the I/O yourself.

ejpa at 2007-7-14 23:29:44 > top of Java-index,Java Essentials,Java Programming...
# 2
All right. What about when you're passing arrays to native methods? Is that a case where ByteBuffer would be better?
Mark_McKaya at 2007-7-14 23:29:44 > top of Java-index,Java Essentials,Java Programming...
# 3
ByteBuffer.allocateDirect() is probably better in that case, if your manipulation is taking place more in JNI-land than in Java-land.
ejpa at 2007-7-14 23:29:44 > top of Java-index,Java Essentials,Java Programming...