• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to get things that I want from an array?  RSS feed

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I can't think of a better way to describe my problem

I have an array of Strings which I have parse into an array with using delimiter, comma



I know the first 6 array string are things that I don't want

I know there are 2 "humans" in this array and each human has 4 attributes

I know the pattern does not change.

How can I extract the human attributes? e.g.

print first human
name, height, weight, age

print second human
name, height weight, age

I know I need one or two for loop in combination to put this pattern in, but I'm kindna lost right now.
help is appreciated
 
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what you are trying to do is (in pseudo code)
1) Ignore 1st 6
2) Take next 4 and process
3) Take next 4 and process

Hint: Array elements can be accessed using an index(which starts with 0)
 
Randy Smith
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:So what you are trying to do is (in pseudo code)
1) Ignore 1st 6
2) Take next 4 and process
3) Take next 4 and process

Hint: Array elements can be accessed using an index(which starts with 0)




please help me out, i'm struck
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you even using the loop?
You can access the elements directly by fields[6],fields[7]...fields[n] right?
 
Randy Smith
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:Why are you even using the loop?
You can access the elements directly by fields[6],fields[7]...fields[n] right?


yes, i am aware that I can access the array directly e.g. fields[n], I need a loop because I have X things in the array.

n is dependent on the X number of items identified in the array



OK..it's NOW FIXED...@_@ thanks anyway...
 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Randy Smith wrote: . . . n is dependent on the X number of items identified in the array . . .
That looks a good way to confuse all users.
 
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Randy Smith wrote:OK..it's NOW FIXED...@_@ thanks anyway...

I suspect you mean that you're no longer getting any errors, which is not the same.

Java is an Object-oriented language, so the normal way to solve your problem would be to create a Human class that has attributes name, height, weight and age and some knowledge of how to parse incoming Strings.

Winston
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!