tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Tools and Libs > Jsoup > Get First and Last Child

Get First and Last Child 

Jsoup is an open source java library for parsing and manipulating HTML with ease. Get the latest binaries from This requires the library jsoup-1.6.1.jar to be in classpath. The following example shows getting the first and last child of an element.

File Name  :  

File Name  :  
Author  :  Sudhakar KV
Email  :  [email protected]
package com.bethecoder.tutorials.jsoup.tests;


import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

public class FirstAndLastChildrenTest {

   @param args
   @throws IOException 
  public static void main(String[] argsthrows IOException {
    InputStream ins = EmptyTest.class.
    Document doc = Jsoup.parse(ins, "UTF-8""");
    System.out.println("Body first Child : " + doc.body().children().first());
    System.out.println("Body last Child : " + doc.body().children().last());


It gives the following output,
File Name  :  OUTPUT


bl  br