1. Member
Join Date
May 2013
Posts
68
Blog Entries
1
Rep Power
0

## array trouble

just a simple question. Can an array have elements stored in increments of floats rather than integers. "ex. array[.1],array[.2],array[.3],array[.1]". reason is because im going by degrees and i rather have a finer tolerance than by 1's.

2. ## Re: array trouble

No. But you can use something like a Map.

Or use ints like usual but define each unit to be as small as you need (like using 150 cents instead of 1.50 dollars).

3. ## Re: array trouble

The index have to be int. If you want a finer tolerance than whole degrees, you can always multiply it by ten (or even a hundred) before storing it in an array though (so a degree of 1.5 would be in array[15]).

4. Member
Join Date
May 2013
Posts
68
Blog Entries
1
Rep Power
0

## Re: array trouble

thanks i like your guys answers, but i just realized only about 4 of my 800 elements in the array would be a non integer. that would be a lot of wasted space i created an array like that. ill just do some ratio work to figure out the degrees that arent intergers. thanks for your help. but one quick question, say i preset my array so i would have enough spaces are all the spaces im not using still take up memory?
Java Code:
`double xxx[] = new double[100000];`

5. ## Re: array trouble

In an array of primitive types (int, long, float etc), I believe it does, yes. In an array of classes, enough space is assigned to contain pointers, which (I think) means four bytes per pointer.

6. Senior Member
Join Date
Jan 2013
Location
Northern Virginia, United States
Posts
5,642
Rep Power
9

## Re: array trouble

Regarding your last question on array size. Use List implementations (e.g. ArrayList). The size is adjusted dynamically to accommodate growth.
Also, try:
Java Code:
```double [] vals = new double[2_000_000_000];
//  need this to get underscores to show -- silly formatter.```
And see what happens.

Regards,
Jim
Last edited by jim829; 07-17-2013 at 09:35 PM. Reason: Array size correction