Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Creating a loop instead of typing each thing out

 
Tyler Tallman
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I am trying to loop through and tic each character in the list below:

q2we4r5ty7u8i9op-[=zxdcfvgbnjmk,.;/'

instead of having to type out stringQ.tic(), string2.tic(), etc. throughout the whole list. All I have is



Any idea where to go from here?

edit: and I named the list of characters above "characters", just to clarify.

edit2: and I should also mention that I have characters in an array, sorry sorry
 
Tyler Tallman
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess what I'm really having trouble with is figuring out where to start off with. I don't know how to loop through in the way that I described, so that everytime I move up one in the array it does another string pluck.
 
Aj Prieto
Ranch Hand
Posts: 75
Android Chrome Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Tyler Tallman
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aj Prieto wrote:


All this would do is give me something like q.tic() or a.tic(), I need to be stringA.tic() or stringQ.tic().
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot construct local variable names on the fly in Java.

You can construct member variable names on the fly using reflection, but there's a 99.99% chance that this would be the wrong approach to whatever problem you're trying to solve.

Based on what you've said so far, you want an array or ArrayList (both of which can be efficiently indexed numerically) or a Map (which provides fast lookup by name).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic