File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

new to working with arrays

 
jon Prais
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch!

What's your approach so far, and where are you having trouble?
 
jon Prais
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
jon Prais
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you that is the info I was looking for to get me started
 
ak pillai
author
Ranch Hand
Posts: 288
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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;

 
Vijay Raj
Ranch Hand
Posts: 110
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 456
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic