This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
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,
Sun Certified Java Programmer 1.5,
Sun Certified Web Component Developer 5.
"No pain. No Gain"
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:
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.
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