Solved

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

Posted on 2012-04-04
2
229 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This video teaches viewers about errors in exception handling.

752 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