File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Creating a loop instead of typing each thing out Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Creating a loop instead of typing each thing out" Watch "Creating a loop instead of typing each thing out" New topic
Author

Creating a loop instead of typing each thing out

Tyler Tallman
Greenhorn

Joined: Oct 04, 2012
Posts: 20

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

Joined: Oct 04, 2012
Posts: 20
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

Joined: Sep 28, 2012
Posts: 72



Da mihi sis bubulae frustum assae, solana tuberosa in modo Gallico fricta ac quassum lactatum coagulatum crassum.
Tyler Tallman
Greenhorn

Joined: Oct 04, 2012
Posts: 20
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

Joined: Jan 03, 2004
Posts: 6109
    
    6

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).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Creating a loop instead of typing each thing out
 
Similar Threads
WA #1.....word association
printing and returning arrays
An array list contains "abc", 3, "xyz", 7: How can i filter the numerals and display
Printing an array using nested for loops? (Code edited)
Calculate the average of an ArrayList