Solved

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

Posted on 2012-04-04
2
228 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 500 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
diffSum example 4 51
egit plugin on eclipse 8 82
even odd program using while loop 3 60
jsp login check 12 43
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…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

830 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