Quick Java Question

EpsiIon

Platinum Member
Nov 26, 2000
2,351
1
0
I'm writing a short Java program for a computer science class that has to be done under a certain size and with a limited number of semi-colons. I've already met the requirements but I'm trying to make my program even more efficient.

Right now I'm looking for a way to traverse an array with only a String and the array. Any variables I declare would not be in the same scope as the traversal, so I can't do that. I can't think of any possible way to do this and could use your help if you can think of a short solution to this problem.

Thanks,
Epsilon
 

purpledemon

Senior member
Jun 21, 2001
291
0
0

what do you have to do while traversing the array ?
just print the value ?

if thats the case .... you could just use the String to store the index and traverse while you System.out the values ?

does that help ?
 

manly

Lifer
Jan 25, 2000
13,087
3,852
136
Integer.valueOf() can parse a String representing a number.

I seriously doubt you could re-use an existing String variable to do array traversal more concisely than you can with the for loop construct (and a dedicated integer index). Although you might save a semicolon, obviously it would be less efficient from a time/space standpoint.
 

m0ti

Senior member
Jul 6, 2001
975
0
0
And Strings are immutable to boot, so using a String over an int (not an Integer) is less efficient.