This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
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


Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
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: 44616
    
  34
Try changing the continuation condition to i < listofvalues.length * 2 and see what happens. You will have to comment out line 5.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Retrieving Value from Array as [cnt % arrayvariable.length]
 
It's not a secret anymore!