Solved

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

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
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:

773 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