Wednesday, April 10, 2013

Java HashSet Example

Java HashSet Example HashSet is the class, which is available in java.util package.  HashSet implements the set interface. HashSet does not preservs the order, suppose if we inert the elments in the HashSet in some order, while  Iterating we can not guarantee to get the same order. HashSet allows the null values. HashSet has the methods like add,remove,size,isEmpty...etc. Java HashSet Sample Code :    import java.util.Iterator; import java.util.HashSet; //HashSet Example Java public class JavaHashSetExample { public...

Java ListIterator Example

Java List Iterator Example: List Iterator is the interface in java.util package. ListIterator has lot of methods which are very much useful based on our real time scenerios. ListIterator has methods which we can iterate in the forward / reverse direction. and ListIterator also have the methods like prviousIndex and nextIndex methods. and it also has set,remove and add methods. I am giving the below very basic ListIterator Sample.  Java List Iterator sample code : import java.util.ArrayList; import java.util.ListIterator; /* * Java...

Sunday, April 7, 2013

Java TreeSet Example

Java TreeSet Example TreeSet is the class which is available in java.util package. The main advantage of TreeSet is, it automatically sorts the elements. TreeSet implements the Set interface, it doesn't allow the Null values and allows unique elements. TreeSet has lot of methods which are very much useful. TreeSet isEmpty() method which checks whether the TreeSet is empty or not. TreeSet methods are remove,removeall, add,addall,contails,contailsall...etc  Java TreeSet Example Code import java.util.Iterator; import java.util.TreeSet; //TreeSet...

Java Enhanced For Loop Example

Java Enhanced For Loop Example : Enhanced For Loop is a more easy way and convenient way to iterate the elements from the collections or Arrays. I am giving very basic Enhanced For Loop Example below. The below code is very straight forward how you iterate the elements over the collections/arrays by using Enhanced For Loop. Enhanced For Loop Example Code  import java.util.ArrayList; //Java Enhanced for Loop Example public class EnhancedForLoopExample { public static void main(String[] args) { String[] array = new String[]...

Saturday, April 6, 2013

Java Iterator Example

Java Iterator Example I am giving the very straight forward example how you Iterate the elements from the ArrayList. Iterator is the interface which is there in the package java.util. You can iterate the elements from the Iterator by using the methods hashNext() and next(). By using remove() method we can remove the elements from the Iterator. Sample code for the Java Iterator Example : import java.util.ArrayList; import java.util.Iterator; /* * JavaIterator Example */ public class JavaIteratorExample { @SuppressWarnings({ "rawtypes",...

 
Disclaimer : If you find any mistakes / corrections / feedback Please let us know...This website author shall not accept liability or responsibility for any errors, mistakes or misstatements found in this website.