I recall seeing, somewhere, an example that stepped through String args[] by deleting the lowest numbered value(s)
public static void main( String args[]) {
while (args.length > 0 ) {
// do something and obliterate elements from args[]
}
}
Obviously, a variable tracking current position in args and compared to args.length will do it; or an ArrayList made from args[]’s contents, with argsAL.size(). Am I mis-remembering an ArrayList example? I know this is a borderline question, the likely answer is, “No, there isn’t and there shouldn’t be either!”. Maybe I’m over-focused…
Bill
No, there isn’t and there shouldn’t be either! Deleting from the front of an array would be a needlessly expensive way to do this.
You might be thinking of many scripting languages having a
shiftoperator to dequeue the next element (perl, bash, etc).Edit: Just for posterity, here’s a pretty simple implementation of Queue that would allow you to “fake” the same functionality (i.e. encapsulate the cursor):
Usage:
Warning: Untested