# Problem ArrayList< float[ ] > inputting new numbers

Page 1 of 1

## 5 Replies - 435 Views - Last Post: 12 January 2013 - 07:34 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=306962&amp;s=b14bd86489849ebb77df3f67246466bc&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

Reputation: 7
• Posts: 236
• Joined: 31-July 09

# Problem ArrayList< float[ ] > inputting new numbers

Posted 12 January 2013 - 06:52 PM

Hi,
I'm a little baffled by this problem okay my float array contains the right float numbers but when I passed them into
my ArrayList that contains a float array the array seems to have new numbers inserted into it

```public void test1()
{

ArrayList<String >sNumbers = new ArrayList< String >();

float[]test = new float[ sNumbers.size() ];

ArrayList< float[] > list = new ArrayList< float[] >();

for( int u = 0; u < test.length; u+=2 )
{
test[ u ] = Float.parseFloat( sNumbers.get( u ) );
System.out.println( test[ u ] );
}

for( int i = 0; i < list.size(); i++ )
{
System.out.println(  i );
System.out.println( "Verts: " + Arrays.toString( list.get( i ) ) );

}
for( int y = 0; y < test.length; y++ )
{
System.out.println( "Verts: " + list.get( 0 )[ y ] );
}

}

```

this prints

1.0
-1.0
1.0
-1.0
0
Verts: [1.0, 0.0, -1.0, 0.0, 1.0, 0.0, -1.0, 0.0]
Verts: 1.0
Verts: 0.0
Verts: -1.0
Verts: 0.0
Verts: 1.0
Verts: 0.0

Is This A Good Question/Topic? 0

## Replies To: Problem ArrayList< float[ ] > inputting new numbers

### #2 FallenG

Reputation: 22
• Posts: 44
• Joined: 12-January 13

## Re: Problem ArrayList< float[ ] > inputting new numbers

Posted 12 January 2013 - 07:11 PM

Well you only filled half the values in test, so the others are initialised to 0.0 by default...

### #3 jon.kiparsky

• Pancakes!

Reputation: 9437
• Posts: 16,361
• Joined: 19-March 11

## Re: Problem ArrayList< float[ ] > inputting new numbers

Posted 12 January 2013 - 07:14 PM

This may be a stupid question, but what are you trying to do here?

I can't make head or tail of it - what's the desired result that you're not getting?

Reputation: 7
• Posts: 236
• Joined: 31-July 09

## Re: Problem ArrayList< float[ ] > inputting new numbers

Posted 12 January 2013 - 07:22 PM

Hi,
I don't want these the numbers 0.0 in the float array

this is the result I'm getting
Verts: [1.0, 0.0, -1.0, 0.0, 1.0, 0.0, -1.0, 0.0]

but I was expecting this result
Verts: [1.0,-1.0,1.0,-1.0 ]

### #5 jon.kiparsky

• Pancakes!

Reputation: 9437
• Posts: 16,361
• Joined: 19-March 11

## Re: Problem ArrayList< float[ ] > inputting new numbers

Posted 12 January 2013 - 07:28 PM

In that case, FallenG has put his finger on it:
```for( int u = 0; u < test.length; u+=2 )
```

Because you increment by twos, you're skipping over the odd-numbered indexes, which remain initialized to zero.

### #6 FallenG

Reputation: 22
• Posts: 44
• Joined: 12-January 13

## Re: Problem ArrayList< float[ ] > inputting new numbers

Posted 12 January 2013 - 07:34 PM

Pin Head, on 12 January 2013 - 07:22 PM, said:

Hi,
I don't want these the numbers 0.0 in the float array

this is the result I'm getting
Verts: [1.0, 0.0, -1.0, 0.0, 1.0, 0.0, -1.0, 0.0]

but I was expecting this result
Verts: [1.0,-1.0,1.0,-1.0 ]

As I said, you created an array with a size twice as large as the number of elements you are filling it with. All values in a [in]Float[][/in] are initialised to [in]0.0[/in] be default.

Perhaps you meant something like this?
```		float[] test = new float[sNumbers.size() / 2];
ArrayList< float[] > list = new ArrayList< float[] >();

for( int u = 0; u < sNumbers.size(); u+=2 )
{
test[ u/2 ] = Float.parseFloat( sNumbers.get( u ) );
}
```