Solved

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

Posted on 2012-04-04
2
225 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
Comment Utility
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
Comment Utility
Thank you.... it does...
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now