aspose file tools*
The moose likes Java in General and the fly likes Retrieving Value from Array as [cnt % arrayvariable.length] Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Retrieving Value from Array as [cnt % arrayvariable.length] " Watch "Retrieving Value from Array as [cnt % arrayvariable.length] " New topic
Author

Retrieving Value from Array as [cnt % arrayvariable.length]

Kumar Navin
Ranch Hand

Joined: May 27, 2004
Posts: 52
Recently I came across a way of retrieving values from an array as below:



The end result of output was the same in both the cases, with % and without %.
What is the advantage/disadvantage when we retrieve like " listofvalues[i % listofvalues.length]" from an array.

Regards,
-Kumar.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39803
    
  28
Try changing the continuation condition to i < listofvalues.length * 2 and see what happens. You will have to comment out line 5.
 
 
subject: Retrieving Value from Array as [cnt % arrayvariable.length]