• 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

Creating a loop instead of typing each thing out

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 75
Android Chrome Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Tyler Tallman
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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().
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
Note to self: don't get into a fist fight with a cactus. Command this tiny ad to do it:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic