Skip to main content

Posts

Showing posts from May, 2011

Using comparable and comparator in java collection

   Comparable    Comparator 1 this interface allows the object to compare itself with another object while sorting the list of such type objects. This interface provide the provision to compare two different objects. 2 The objects those implements Comparable interface are sorted automatically without specifying any other comparator. Comparator is passed as arguments to the method who need to sort some objects. 3 less flexible more flexible 4 uses compareTo (object2) method it has compare (object1,object2) method 5 this interface is not a part of collection API. It belongs to java.lang Packages this interface belongs to java.util package. Using Comparable package  collection.examples; import  java.util. ArrayList ; import  java.util. Collections ; class  Contact  implements   Comparable < Contact > {      String  name;      String  email;      int  phone;      pub

Regular Expressions in java

Regular expressions defines the rule or pattern for the string litral. These rule can check the strings for common characteriscs to be followed by all string literal. For example email string must contain @ sybol and the rule for this may be ".+@." . Regular expression is used to express the some portion or structure of the strings. Use of Regular expression to search string in paragraph or line. to edit the specific portion of test into paragraph to validate the string to specified the rules for the server rewrite In java programming languge you can use java.util.regex API to working with regular expressions. this API provides all supported class to use the regular expresion into you project. in the java.util.reges API, there are three classes to be used to deal with regular expression. Pattern class is used to create the object that is the compliled representtation of reqular expression specified by you. Matcher class's object wo