Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Java: how to index each line of the document? thx

Posted on 2012-04-04
2
Medium Priority
?
232 Views
Last Modified: 2012-04-05
Hello Experts,

Please see code below:

//counts the total number of lines
Document doc = logArea.getDocument();
int ctr=0;
ElementIterator elmIt = new ElementIterator(doc.getDefaultRootElement());
 while((elmIt.next() != null)){
      ctr++;
 } // works ok

//how do I index each of the lines? so I can reference a line using an int

Thanks for all of your help...

regards,
0
Comment
Question by:epifanio67
2 Comments
 
LVL 23

Accepted Solution

by:
wdosanjos earned 2000 total points
ID: 37809389
Try this.
Document doc = logArea.getDocument();
int ctr=0;
ArrayList<Element> lines = new ArrayList<Element>();
ElementIterator elmIt = new ElementIterator(doc.getDefaultRootElement());

while((elmIt.next() != null)){
    lines.add(elmIt.current());
    ctr++;
} // works ok

lines.get(0); // gets the first line

Open in new window


I hope this helps.
0
 

Author Closing Comment

by:epifanio67
ID: 37813169
Thank you.... it does...
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question