Forums Register Login

Alternative to String.split()

+Pie Number of slices to send: Send
Hi Folks,
In my code, I am attempting to split a String.
The String I have to split is huge and so this method returns very very big array causing heap space problems.
I have considered first splitting the String into smaller managable Strings and then splitting them but it looks a little messy to me.

Could you please suggest a more efficient and cleaner way to do this.

Thanks in advance,
Royston
+Pie Number of slices to send: Send
You could use StringTokenizer, but that can't handle regular expressions to split on, only single characters. The alternative is to use Pattern and Matcher; in fact these are also used by String.split (which in fact uses Pattern.split). Roughly speaking:
+Pie Number of slices to send: Send
Is the string regular? In other words, can it be parsed? Is it line-oriented (or other delimiter)? Why is it so big?
+Pie Number of slices to send: Send
Thanks a lot Rob. The parser and Matcher worked like a breeze perfectly.



The String is a set of input messages that my code gets to work on. I am given this large string to parse and convert in to another format. It is a regular String that has to be parsed/split with \n \r as the delimiter.


David Newton
Post Friday, September 04, 2009 7:20:51 PM Subject: Alternative to String.split()
Is the string regular? In other words, can it be parsed? Is it line-oriented (or other delimiter)? Why is it so big?



Apologies for the delay. Was on holiday during the weekend
+Pie Number of slices to send: Send
If \n and \r are the delimiters, perhaps a BufferedReader wrapped around a StringReader is a better idea.
+Pie Number of slices to send: Send
You can use reference/related examples from www.java2examples.com for more details
+Pie Number of slices to send: Send
Thanks guys
Think of how dumb the average person is. Mathematically, half of them are EVEN DUMBER. Smart tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 17922 times.
Similar Threads
reg split method in string
split method in java
splitting arrays
On windows - One CPU , Two Monitors, Two kwyboards, Two mouse
String split
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 00:14:48.