943,648 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 3613
  • Java RSS
Nov 18th, 2008
0

tab separated file

Expand Post »
I have a file that is tab separated. i read it in as an arraylist<string> how can i print out only the second section of the file?
Similar Threads
Reputation Points: 7
Solved Threads: 0
Junior Poster
mrjoli021 is offline Offline
170 posts
since Mar 2007
Nov 18th, 2008
0

Re: tab separated file

That depends what "second section" means. If you can't be more specific than that, you have little chance of getting a program to do something with it.
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 838
Posting Genius
Ezzaral is offline Offline
6,756 posts
since May 2007
Nov 18th, 2008
0

Re: tab separated file

the file is tab separated into three sections.

section1 section2 section3

i only want to read section2
Reputation Points: 7
Solved Threads: 0
Junior Poster
mrjoli021 is offline Offline
170 posts
since Mar 2007
Nov 18th, 2008
0

Re: tab separated file

Then use String.split() to separate it and read the second element of the result.
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 838
Posting Genius
Ezzaral is offline Offline
6,756 posts
since May 2007
Nov 18th, 2008
0

Re: tab separated file

array is an arraylist<string>

Java Syntax (Toggle Plain Text)
  1. for (int i = 0; i<array.size(); i++)
  2. {
  3. System.out.println(array.get(i).split(" "));
  4.  
  5. }

i get: [Ljava.lang.String;@ca0b6

i am supposed to get "10.0.0.2"
Reputation Points: 7
Solved Threads: 0
Junior Poster
mrjoli021 is offline Offline
170 posts
since Mar 2007
Nov 18th, 2008
0

Re: tab separated file

Did you read the api doc on split() at all?
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 838
Posting Genius
Ezzaral is offline Offline
6,756 posts
since May 2007
Nov 18th, 2008
0

Re: tab separated file

yes and according to the instructions that is how u should use it.
Reputation Points: 7
Solved Threads: 0
Junior Poster
mrjoli021 is offline Offline
170 posts
since Mar 2007
Nov 18th, 2008
0

Re: tab separated file

Really? Because this particular part would seem to be clearly saying something else
Quote ...
Returns:
the array of strings computed by splitting this string around matches of the given regular expression
Notice the array part.

(Also, there does not appear to be anyone named "u" here at the moment. Use proper English.)
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 838
Posting Genius
Ezzaral is offline Offline
6,756 posts
since May 2007
Nov 18th, 2008
0

Re: tab separated file

i read it again and i still understand the same thing.

i obiously dont understand how to use it.

can you help me out or not.
Reputation Points: 7
Solved Threads: 0
Junior Poster
mrjoli021 is offline Offline
170 posts
since Mar 2007
Nov 18th, 2008
0

Re: tab separated file

It splits on a particular expression, which in your case should be tab, and returns an array of the pieces. If you want the second section then you just need the second element of that array.
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 838
Posting Genius
Ezzaral is offline Offline
6,756 posts
since May 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Set Classpath for application in JBoss
Next Thread in Java Forum Timeline: Help with an error...





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC