This week's giveaway is in the Spring forum.
We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!
See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to group?

 
Jay Orsaw
Ranch Hand
Posts: 356
Android Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kind of a vague question, but didn't know how to ask it. Basically I have a this set of code, I posted the first 2 of 6, and I wanted to know how I would be able to reduce this into 1?

basically the code is EXACTLY the same besides f1,f2,f3,....,f6.




I figured I might be able to do something like f(n) or something like that, but I don't know.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15203
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of having six variables f1, f2, f3, ..., f6 you could create an array.

Have a look at: The Java Tutorials - Arrays.

For example:

Access the six elements of the array as f[0], f[1], f[2], ..., f[5]. Ofcourse you can use a variable to index into the array:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic