Archive

Archive for the ‘Java’ Category

ListIterator

August 25, 2009 Leave a comment

java.util.List,the List interface places additional methods, other than those specified in the Collection interface.
On the contracts of the iterator, add, remove.. Some additional methods are added in the List interface. Two of them are here

public abstract java.util.ListIterator listIterator();
public abstract java.util.ListIterator listIterator(int);

The List interface provides a special iterator, called a ListIterator,That allows element insertion and replacement, and bidirectional access, means you can travel through iterator forward and backward while iterating you can add and remove objects from the List implementations.

You can not modify the List directly while iterates through the Iterators

See the following example of ListIterator

import java.util.Arrays;

import java.util.ListIterator;

import java.util.List;

public class ListIteratorTest {

   public static void main(String args[]) {

      List nameList = new ArraysList();
      nameList.add(“one”);
      nameList.add(“two”);
      nameList.add(“three”);

      ListIterator itr = nameList.listIterator();

      while (itr.hasNext()) {

      String name = itr.next();

      System.out.println(name);

      // based on some operation you are adding object to list

      if (name.equals(“three”)) {

      itr.add(“four”);

      }

      }
   
   }

}

Categories: Java

Started an Open source project

August 12, 2009 1 comment

Hi all.

I have started an open source project for converting pojo to xml and xml to pojo. Project was started while i was consulting a swiss bank product development. There was a requirement for converting POJO to xml. We were using xmlbeans at that time. But Some of the xml are not having the schema or DTD. So the people were just append the tags and values in StringBuffer and produced the output. But i have idea to write simple light weight API  for converting the Transfer Object directly to an xml using reflection API.So the Class name and properties have to declare based on xml element you want. Now i am planning to make that small program to available to every one as an open source project. If any one is interested in contributing the project reply me.

first release will be available on sourceforge.net soon.

Thanks

Hari.

Categories: Java
Follow

Get every new post delivered to your Inbox.