Win a copy of Learning Regular Expressions this week in the General Computing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

How to create this String array  RSS feed

 
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
 
Sheriff
Posts: 21462
96
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: 21462
96
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.
 
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: 21462
96
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!