Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Java String Split

807588Feb 5 2009 — edited Feb 9 2009
Hey there. I have a text file with many lines that look like this:
AT3G61200       "\t"        ABNORMAL INFLORESCENCE MERISTEM (AIM1)
It's a tab between those words.

My first step is to split the lines on "\t". That works. AT3G61200 is stored in hei[0] and ABNORMAL INFLORESCENCE MERISTEM (AIM1) is stored in hei[1]. Further i will splitt hei[1] on the parantese "\\(". I write out tmp[0], and I get what I want. There is many empty strings, so therefor I have the -1. BUT BUT BUT, when I want to write out the "AIM1" that I thought would be stored in tmp[1], I get an array out of bound exception. The tmp table only store the string BEFORE the parantese. Why?

I tried to write hei[1] to a text file, to maybe try to load only that file in and then only split on the parantese, but the text file was blank. Even if I tried to write hei[0] to a text file which is not going to be splitted. When I removed -1 from the split command, then I could write hei[0] to a text file, but of course not hei[1] since it contains many empty strings. Why???

I need help here, I think this is weird :S
	public static void main(String[] args) {
		
		try {
			
			FileReader fr = new FileReader("mytextfile");
			BufferedReader br = new BufferedReader(fr);
			String line;
			
			while ((line = br.readLine()) != null) {
				
				String[] hei = line.split("\\t",-1);
				String[] tmp = hei[2].split("\\(", -1);
			
				System.out.println(tmp[0]);
// System.out.println(tmp[1]); -- DONT WORK
Edited by: knx on Feb 5, 2009 6:44 AM

Edited by: knx on Feb 5, 2009 6:45 AM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 9 2009
Added on Feb 5 2009
47 comments
1,384 views