8 Replies - 394 Views - Last Post: 20 July 2011 - 09:33 PM Rate Topic: -----

#1 codecook  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 34
  • Joined: 16-July 11

Looping and making new arrays

Posted 20 July 2011 - 01:10 PM

I was just wondering if its possible to loop and when you get a number or whatever you like from that loop to add it to make a new array and add it to that.

For example:
numbers[] goodNumbers = new numbers [3];



can I put something like in the loop:
numbers[] goodNumbers + x = new numbers [3];
x++;



Then whenever i get something that meets criteria, I could use the goodNumbers + x.add(1) , goodNumbers + x.add(2) , goodNumbers + x.add(3)

This post has been edited by codecook: 20 July 2011 - 01:10 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Looping and making new arrays

#2 CasiOo  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1423
  • View blog
  • Posts: 3,165
  • Joined: 05-April 11

Re: Looping and making new arrays

Posted 20 July 2011 - 01:50 PM

I don't quite understand what you are trying to do
Was This Post Helpful? 0
  • +
  • -

#3 codecook  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 34
  • Joined: 16-July 11

Re: Looping and making new arrays

Posted 20 July 2011 - 02:10 PM

Im looping through random numbers and when i find the ones that meet my criteria, I would like to create a new array for them so they are remembered. so at the ned of the loop i might have 200 of such arrays that hold 3 numbers each. like: {2,5,6},ect..
Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10803
  • View blog
  • Posts: 40,261
  • Joined: 27-December 08

Re: Looping and making new arrays

Posted 20 July 2011 - 02:26 PM

Lists have methods like add(), remove(), get(), set(), etc. Arrays do not. You may consider using an ArrayList<Integer> over an array.
Was This Post Helpful? 2
  • +
  • -

#5 codecook  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 34
  • Joined: 16-July 11

Re: Looping and making new arrays

Posted 20 July 2011 - 02:41 PM

I just read about multidimentional arrays which I may be able to use multiple arrays in one like:

int[][] a2 = new int[100][3]; which give me 3 colums and 100 rowns

View Postmacosxnerd101, on 20 July 2011 - 02:26 PM, said:

Lists have methods like add(), remove(), get(), set(), etc. Arrays do not. You may consider using an ArrayList<Integer> over an array.


How would I loop and make new instances of those lists?

This post has been edited by codecook: 20 July 2011 - 02:42 PM

Was This Post Helpful? 0
  • +
  • -

#6 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10803
  • View blog
  • Posts: 40,261
  • Joined: 27-December 08

Re: Looping and making new arrays

Posted 20 July 2011 - 02:41 PM

Is this about your multiplying matrices project?
Was This Post Helpful? 0
  • +
  • -

#7 codecook  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 34
  • Joined: 16-July 11

Re: Looping and making new arrays

Posted 20 July 2011 - 03:22 PM

Lol, not at all. Its just a puzzle im trying to solve but it involves programming because i will not be able to crunch all those numbers on a calculator.

BTW, Multi-dimentional arrays are perfect for what i need(i hope)
Was This Post Helpful? 0
  • +
  • -

#8 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8346
  • View blog
  • Posts: 31,904
  • Joined: 06-March 08

Re: Looping and making new arrays

Posted 20 July 2011 - 08:36 PM

Will every row in your having 3 columns ? In that case array[100][3] will do the job or can array[5] have 2 columns, array[7] 3 colomns, array[45] 1 column ?
Was This Post Helpful? 1
  • +
  • -

#9 immeraufdemhund  Icon User is offline

  • D.I.C Regular

Reputation: 79
  • View blog
  • Posts: 495
  • Joined: 29-March 10

Re: Looping and making new arrays

Posted 20 July 2011 - 09:33 PM

by the sounds of it a List is going to be what you need. Because if you pull out certain elements from your array you will have 2 different size arrays. Not always a problem, but if you use multidimensional arrays You will have to add a test to see if there is a number for a given index. But if you use a list you can just get the size of the list and do what you need to do with it.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1