2

I was wondering what is the quickest way of storing a byte[] with an integer index in java without using Maps, TreeMap, ArrayLists etc.

i.e. not like this:

private Map<Integer, byte[]> example = new TreeMap()
7
  • 4
    Why can't you use those things you've listed? Commented Feb 15, 2010 at 20:37
  • Just wondering if there is a faster way of doing it. Commented Feb 15, 2010 at 20:39
  • 4
    It sounds like you're optimizing prematurely. Don't Commented Feb 15, 2010 at 20:41
  • nothing I was just wondering the best way to do it as byte[][] looks a little dirty. I was planning to use byte[][]. Commented Feb 15, 2010 at 20:42
  • If you want to know the fastest way, ask for the fastest way. Not "The fastest way except for {x}", because then if {x} does happen to be the fastest way, you're going to get soemthing that doesn't solve your problem. Commented Feb 15, 2010 at 20:42

3 Answers 3

2
private byte[][] example;
example = new byte[][ARRAYS_COUNT];
example[0] = new byte[10];
example[1] = new byte[20];
...
Sign up to request clarification or add additional context in comments.

2 Comments

He wanted to hold them with an integer index.
I don't know how would you use this data structure so can't say for sure is this more efficient or not. For example, if you want to store 3 byte arrays with indexes, say, 0, 1 and 10000000, this is definitely less efficient than TreeMap.
1

Quickest way would be an ArrayList<byte[]>, or you want or not. A byte[][] isn't going to work as you can then hold only 28-1 arrays, not 232-1 as you could with an integer index which you explicitly mentioned in your question.

1 Comment

Ah yes ArrayLists, I think ill try a few and see whats quickest. Thanks
0

How about byte[][] and resize as appropriate? Not as good as an ArrayList but you banned that...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.