permaculture playing cards*
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "arrays" Watch "arrays" New topic
Author

arrays

kevin schmidt
Ranch Hand

Joined: Aug 24, 2001
Posts: 85
Hi,
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.
kevin
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1506
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.

Bosun


Bosun (SCJP, SCWCD)
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).
Jason
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Kevin
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.
Dave


Dave
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
Greenhorn

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"
Sheriff

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: http://aspose.com/file-tools
 
subject: arrays
 
Similar Threads
Slight Swing Layout issue
String array of main
Question about Properties
String --> split/regex question
how Arraylist work internally?