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


kevin schmidt
Ranch Hand

Joined: Aug 24, 2001
Posts: 85
Say a person enters empty information into an array and wants to get rid of the empty space. Is there a way of getting rid of the empty space in an array? TIA.
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
Assuming oyu are referring to a String or character array. You can check the array ocurence for spacs(s) and then replace it with whatever it's supposed to contain.


So much trouble in the world -- Bob Marley
jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
arrays are immutable, once they are created, their size can not be changed. If you want a collection that will change in size, use an ArrayList instead (or if you need sychronization, use a Vector).
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
If you have to use arrays just iterate over the first array and every piece of valid data add to a new array and ignore the invalid elements. Then set the original array null. If you dont have use arrays then Jasons suggesttion of an ArrayList or Vector is your best bet.

Argm Mastoi
Ranch Hand

Joined: Oct 16, 2001
Posts: 35
Kevin, i understood 3 things from your query:
1. Rather u want to trim spaces in strings elements of an array
2 : or u have eneterd just spaces and want to edit it.
3. there are spaces in between the string that u want to remove.
for 1. u have to run a loop and trim every elemetnt with String.trim() method or for 2. u can re-enter the values for 3. run a loop and search for spaces in every element and replace them. ihope it's clear
[This message has been edited by Marilyn deQueiroz (edited November 03, 2001).]
Argm Mastoi
Ranch Hand

Joined: Oct 16, 2001
Posts: 35
I'm sorry i don't know how this smily came, i didn't wanted to add it
Sreenivasa Majji
Ranch Hand

Joined: Jul 12, 2001
Posts: 224
While posting/replying a question, just check the "Disable Smilies in This Post" check box.

Sreenivasa Kumar Majji
Sun Certified Java Programmer
SCJP Mock Test

Sreenivasa Majji
sami syed abdul

Joined: Nov 02, 2001
Posts: 2
well i have just started learing java and plan to give the SCJP in three months how should i prepare any advice
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
Read ALOT.
Practice coding ALOT.
Take bunches of Mock exams.
Go through the JavaRanch forums ALOT.
Three months you say. hmmmmm. Hope that Java is not your first object oriented language, and certainly not your first computer language.
Check out The BunkHouse for reviews of lots of Java books. Especially the Beginner and Certification sections.

"JavaRanch, where the deer and the Certified play" - David O'Meara
I agree. Here's the link:
subject: arrays
It's not a secret anymore!