File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes new to working with arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "new to working with arrays" Watch "new to working with arrays" New topic
Author

new to working with arrays

jon Prais
Greenhorn

Joined: Mar 16, 2006
Posts: 3
I have a problem and would like to know how best to approach
solving it.

I have an array of strings that need to be put in reverse order.

So I need to read the array the process it and reverse the strings..

any help would be great.

Please let me know if there is anything that needs to be cleared up

Thanks
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Welcome to JavaRanch!

What's your approach so far, and where are you having trouble?


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
jon Prais
Greenhorn

Joined: Mar 16, 2006
Posts: 3
I am also new to programming.

Since I don't know the length of the array I decided to you and arraylist(). From what I have read you need to dfine an array length and once it is set you cannot chat it without deleteing and redefining it.

Is that the right approach.

I look at the java code and think I could use some of these methods but not exactly sure how to approach the problem..

looking more or less for some psuedo code that will help me with thte thought process.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

You should start by reading some basic material on arrays.
Sun Tutorial is a good place to start :
http://java.sun.com/docs/books/tutorial/java/data/arrays.html


[My Blog]
All roads lead to JavaRanch
jon Prais
Greenhorn

Joined: Mar 16, 2006
Posts: 3
thank you that is the info I was looking for to get me started
ak pillai
author
Ranch Hand

Joined: Feb 11, 2006
Posts: 288
Java Collection framework is very powerful. It also has some utility classes for lot of algorithmic stuff like sorting, reversing, shuffling etc in java.util.Collections and java.util.Arrays. Here is a sample code:

import java.util.Arrays;
import java.util.Collections;
import java.util.List;



java j2ee job interview questions with answers | Learn the core concepts and the key areas
Vijay Raj
Ranch Hand

Joined: Oct 10, 2005
Posts: 110
The OP wanted to reverse the string and not the array. This would reverse the string in the array.



Jon Prais, you need to study the language first and only then will you be able to sollve problems. I should not be posting solutions here but did it because I wanted to show that you can solve the problem without having the length of the array. You can get the length of the array using arrayName.length(i.e. arr.length from above example)

The above code uses the enhanced for-loop. You need Java 5 compiler.

regards,
vijay.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

The above code uses the enhanced for-loop. You need Java 5 compiler

I would recommend to know how to do it the classic way.
Everybody should know how to get the size of an array.
Jan Groth
Ranch Hand

Joined: Feb 03, 2004
Posts: 456
@Vijay

talking about java 5 - a StringBuilder would be more appropriate to use (new in J5), because it does not come with synchronisation-overhead...



regards,
jan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: new to working with arrays