Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

string array split into separate variables including another array  RSS feed

 
Kelly Liles
Greenhorn
Posts: 2
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First time on the board so I hope my posting makes sense.

how do I get the for loop on the array to recognize the array as acceptable variable? The split is to take the string array it is passed and separate out each piece into it's own variable so it can be adjusted directly. This is a segment of code on the issue I am having. If needed both files please let me know as I can attach them. Well, once I figure out what file types I can upload.

Thank you for any help you can provide.

----adds in the varibles from the string that is passed and is manipulating.

 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kelly Liles wrote:First time on the board so I hope my posting makes sense.

Hi Kelly, and welcome to JavaRanch.

Your post is just fine, and thanks for using code tags straight off the bat ... you'd be surprised how many don't

I think you may be looking at this a bit "procedurally" rather than in terms of "objects".
What if all that stuff inside your loop was in a Part constructor instead? viz:and now your loop becomes:and no need for any "add()" method.

Not everyone will agree with this advice, and there are certainly other ways to do it, but I reckon that objects (or classes) should know how to construct themselves in whatever way is needed.
But whatever you decide, I would definitely take that code out of your loop.

BTW, by convention, 'Parts_List' should be 'partsList'. Variables should always start with a lower-case letter, and underscores ('_') are usually reserved for things like constants or enum instance names.

HIH

Winston
 
Kelly Liles
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Winston,

thanks for the help. I think that makes sense to me and what understanding I have of Java. I am going to try it out and see if that resolve its it. I hope to post a successful update soon.

thanks,
Kelly
 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kelly Liles wrote:I hope to post a successful update soon.

Good luck. Just remember that it's by no means the only way to do it, and you might want to try out a few "variations" yourself; but hopefully, it's got you thinking...

Winston
 
Norm Radder
Ranch Foreman
Posts: 2240
28
 
Knute Snortum
Sheriff
Posts: 4073
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Kelly Liles: It's not a problem that you posted this question in two different forums, but we like it if you simply state that you have done so.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!