• Post Reply Bookmark Topic Watch Topic
  • New Topic

parse string to int in 2d arrays  RSS feed

 
Talal Mohammed
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is it possible to parse one column of a 2d array to int ? this will make it more clear:

for example i have 2 columns
Age-Sex column } different 1d array not included
20 | F | row} 2d array
21 | F |
and so on...
the first index for the age is array[0][0]
the next index will be --------array[0][1]
next and so on...--------------------[0][2]
and so on the same sequence is there regardless of the number of columns there will be a specific number that will increment in a sequence such as 5 - 5 - 5 however in this case its 1 - 1 -1...
so what im asking is, is it possible to form a for loop that will increment and parse indexes in this manner?
thank you
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is not clear at all, at least not to me. Can you explain it again. Can you create some real code which holds example data, and show example of real input or output that you are having trouble reading or making or whatever?
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Talal Mohammed wrote:is it possible to parse one column of a 2d array to int ? this will make it more clear:

for example i have 2 columns
Age-Sex column } different 1d array not included
20 | F | row} 2d array
21 | F |
and so on...
the first index for the age is array[0][0]
the next index will be --------array[0][1]
next and so on...

No it won't. If it is indeed a column (which it appears to be) the first age will be [0][0] and the next will be [1][0] ... and so on.

But Steve is quite right. We need to know more about what you want. Just for starters, where does this data come from?

Winston
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Talal Mohammed wrote:is it possible to parse one column of a 2d array to int ?. . .
No, because there is no such thing as a 2D array. There are only arrays of arrays, which are better than 2D arrays anyway.
That is not object-oriented programming. you should create a class to encapsulate that information, and use those Strings in its constructor. Then you can parse one of the Strings in your split String[] to an int, probably with the methods of the Integer class.
 
Talal Mohammed
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well what i was thinking of is asking for user input to store data about goods, name, barcode, quantity available and so on... i agree with you Campbell Ritchie i will create a class that holds this information, however can you explain more about how will i be able to parse the data that i need, i see you mentioned 'split string', can you elaborate or give me a link of what a split string is. thank you for all your comments <3
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!