• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

new to working with arrays

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you that is the info I was looking for to get me started
 
author
Posts: 288
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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;

 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic