• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

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).
 
Yeah, but how did the squirrel get in there? Was it because of the tiny ad?
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic