• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to create this String array  RSS feed

 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
i wonder how i can create a String array from the following output code:

thanks in advance
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What kind of array do you need? A one-dimensional array? A two-dimensional array?
 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1 dimension; something like { "0", "0.1", "0.2", and so on }
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, what have you tried so far? You know the number of elements (20 times 1 (for i only) plus 10 (for i and j). you should be able to find a way to access the array in a sequential order. So you should be able to solve this.
 
J. Sellin
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


how about this?
 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:Well, what have you tried so far? You know the number of elements (20 times 1 (for i only) plus 10 (for i and j). You should be able to find a way to access the array in a sequential order. So you should be able to solve this.


actually i'm working with legacy code and i want to populate this combo (more exactly, a ComboBoxCellEditor, which i cant find out inside java documentation...); anyway i tried something like:

but i do need a String array to pass to that dreaded ComboBoxCellEditor

that's what i've got...
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's a good start, but has one issue: you're missing the 0, 1, 2, etc.
You may also want to choose to use a few constants:
If you want to switch to 20 for J, all you need to do is change one constant and recompile.

Edit: hmmm, I mistook J Sellin for Miguel...
J Selling, please do not provide full answers like this. LetThemDoTheirOwnHomework.

Miguel, your solution works but it uses a dynamic structure (to be precise, in the background it uses a Vector which is like an ArrayList). In the end it uses a similar technique though - simply write to the next element of the array (Vector has one internally).
 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
your help was quite apreciated, thank you both
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!