Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

empty vector cells

 
Timo Lumme
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

heres what im doing:
im reading from text file some numbers and adding into vector
and before that im removing whitespaces etc, but into vector
goes too enter or null, allways after newline(?) from text file.

im reading BufferedReader byte at a time, converting it to char/string and
adding it into vector, but how i go thru the vector removing null
cells from there or how skip it not adding null data into vector,
cos i cant get any ascii code for it.

thanks
 
Ajay Singh
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I good idea would be to check the value you want to insert to vector is valid. So, wrap the add around if condition,

 
Timo Lumme
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
heres the if see what i mean.
--

 
Ajay Singh
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you not using readLine function?
 
Timo Lumme
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
cos, idea is to control the data flow from the vector out.
want to print/output example 100 numbers then enter and next
100 numbers out to a text file. with printline how do i control
from the vector if its on chunck of line in there, out one char?
 
Ajay Singh
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am confused here... Help in trying understand the situation here,the input file consists of numbers and you want to read them,
remove \r and \n or any other whitespace character and output it to the output stream?
 
Timo Lumme
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah, that the idea, sorry being so confused.

have a program called super pi, and prints out to a
text file many pii numbers, and then try resort it
by removing any spaces etc and writing out line of
100 numbers to output file at a time the enter.

my thought is that the file whice im deal with is
like 35mb full off numbers, and reading into a vector
chunk of like 10000 numbers at time then, printing it
out to file 100 numbers at once, then enter, next 100 numbers
and so on.

maybe im bit offtrack cos i might not need that vector after all
just thought that it would be faster with a vector or an array[].
:roll:
 
Ajay Singh
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Few suggestions:
1. Use ArrayList and give a hint to size, like
List list = new ArrayList(100);
2. To read it easily use StreamTokenizer
http://java.sun.com/j2se/1.5.0/docs/api/java/io/StreamTokenizer.html
http://www.exampledepot.com/egs/java.io/ParseJava.html
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic