aspose file tools*
The moose likes Beginning Java and the fly likes array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "array" Watch "array" New topic
Author

array

bharath pawan
Greenhorn

Joined: Jan 25, 2007
Posts: 11
how to reverse an array with out using indexing
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
Please explain what you mean by "with out using indexing".


Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
Somebody is having you on, surely?

How are you expected to gain access to the elements of an array other than by using their index?
If you have two indices to an array, let's call them i and j, it is very easy to swap the two, with a method like this.. . . and once you have got that working it is easy to use that method to reverse the whole array. But I can't think how you are supposed to do it without using the index.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19722
    
  20

You could do this in C(++) because of pointer arithmetic, but in Java that doesn't exist.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18669
    
    8

Suggested framework:

1. Copy the array to a List (using Arrays.asList)

2. Create a Stack from that List.

3. Create a new empty Stack.

4. Pop entries from the first Stack and push them into the second Stack.

5. Make the second Stack into an array (using List.toArray).
Guido Sautter
Ranch Hand

Joined: Dec 22, 2004
Posts: 142
If we're already converting the array into some sort of Java Collection, maybe java.util.Collections provides some useful methods ...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: array