• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to get things that I want from an array?

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic