Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

arrays

 
kevin schmidt
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Argm Mastoi
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sorry i don't know how this smily came, i didn't wanted to add it
 
Sreenivasa Majji
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
sami syed abdul
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic