News:

MyKidsDiary.in :: Capture your kids magical moment and create your Online Private Diary for your kids

Main Menu

Collator Class Example

Started by VelMurugan, Jan 23, 2009, 09:24 PM

Previous topic - Next topic

VelMurugan

Collator SetStrength() Example

Sets this Collator's strength property.

Collatorclass SetStrength() method example. This example shows you how to use SetStrength() method.This method Sets this Collator's strength property.

Here is the code:-

/*
* @Program that Sets this Collator's strength property.
* SetStrength.java
* Author:-RoseIndia Team
* Date:-16-Jun-2008
*/
import java.util.*;
import java.text.*;
public class SetStrength {
public static void main(String[] args) {
Collator collate = Collator.getInstance(new Locale("US"));
int i=collate.getStrength();
System.out.println("Strength of this Collator is: "+i);
//Sets this Collator's strength property.
collate.setStrength(3);
int j=collate.getStrength();
System.out.println("Strength of this Collator is: "+j);
    }

}


Output of the program:-

Strength of this Collator is: 2
Strength of this Collator is: 3

Source : codingdiary

VelMurugan

Collator SetDecomposition() Example

Set the decomposition mode of this Collator.

Collatorclass SetDecomposition() method example. This example shows you how to use SetDecomposition() method.This method Set the decomposition mode of this Collator.

Here is the code:-

/*
* @Program that Set the decomposition mode of this Collator.
* SetDecomposition.java
* Author:-RoseIndia Team
* Date:-16-Jun-2008
*/
import java.util.*;
import java.text.*;
public class SetDecomposition {
public static void main(String[] args) {
Collator collate = Collator.getInstance(new Locale("US"));
int i=collate.getDecomposition();
System.out.println("Decomposition mode of this Collator is: "+i);
//Set the decomposition mode of this Collator.
collate.setDecomposition(2);
int j=collate.getDecomposition();
System.out.println("Decomposition mode of this Collator is: "+j);
    }

}

Output of the program:-

Decomposition mode of this Collator is: 0
Decomposition mode of this Collator is: 2

VelMurugan

Collator HashCode() Example

Generates the hash code for this Collator.

Collatorclass HashCode() method example. This example shows you how to use HashCode() method.This method Generates the hash code for this Collator.

Here is the code:-

/*
* @Program that Generates the hash code for this Collator.
* HashCode.java
* Author:-RoseIndia Team
* Date:-16-Jun-2008
*/
import java.util.*;
import java.text.*;
public class HashCode {
public static void main(String[] args) {
Collator collate = Collator.getInstance();
  //Returns this Collator's strength property.
  int i=collate.hashCode();
    System.out.println("Hash code for this Collator. is: "+i);
    }

}


Output of the program:-

Hash code for this Collator. is: 681002966

VelMurugan

Collator GetStrength() Example

Returns this Collator's strength property.

Collatorclass GetStrength() method example. This example shows you how to use GetStrength() method.This method Returns this Collator's strength property.

Here is the code:-

/*
* @Program that Returns this Collator's strength property.
* GetStrength.java
* Author:-RoseIndia Team
* Date:-16-Jun-2008
*/
import java.util.*;
import java.text.*;

public class GetStrength {
public static void main(String[] args) {
  Collator collate = Collator.getInstance();
  //Returns this Collator's strength property.
  int i=collate.getStrength();
    System.out.println("Collator's strength is: "+i);
    }

}


Output of the program:-

Collator's strength is: 2

VelMurugan

Collator GetInstance() Example

Gets the Collator for the current default locale.

Collatorclass GetInstance() method example. This example shows you how to use GetInstance() method.This method Gets the Collator for the current default locale.

Here is the code:-

/*
* @Program that Gets the Collator for the current default locale.
* GetInstance.java
* Author:-RoseIndia Team
* Date:-16-Jun-2008
*/
import java.util.*;
import java.text.*;
public class GetInstance {
public static void main(String[] args) {
// Build a vector of words to be sorted
    ArrayList list = new ArrayList();
    list.add("R");
    list.add("O");
    list.add("S");
    list.add("E");
     Collator collate = Collator.getInstance();
    CollationKey[] keys = new CollationKey[list.size()];
    for (int k = 0; k < list.size(); k ++)
      keys[k] = collate.getCollationKey((String)list.get(k));
    for (int l= 0;l < keys.length; l++) {
      System.out.println(keys[l].getSourceString());
    }
   }
}

   


Output of the program:-


R
O
S
E

VelMurugan

Collator GetDecomposition() Example

Get the decomposition mode of this Collator.

Collatorclass GetDecomposition() method example. This example shows you how to use GetDecomposition() method.This method Get the decomposition mode of this Collator.

Here is the code:-


/*
* @Program that Get the decomposition mode of this Collator.
* GetDecomposition.java
* Author:-RoseIndia Team
* Date:-16-Jun-2008
*/

import java.util.*;
import java.text.*;

public class GetDecomposition {
public static void main(String[] args) {
Collator collate = Collator.getInstance(new Locale("US"));
int i=collate.getDecomposition();
System.out.println("Decomposition mode of this Collator is: "+i);
    }
}


Output of the program:-

Decomposition mode of this Collator is: 0

VelMurugan

Collator GetCollationKey() Example

Transforms the String into a series of bits that can be compared bitwise to other CollationKeys.

Collatorclass GetCollationKey() method example. This example shows you how to use GetCollationKey() method.This method Transforms the String into a series of bits that can be compared bitwise to other CollationKeys.

Here is the code:-

/*
* @Program that Transforms the String into a series of bits that can be
   compared bitwise to other CollationKeys.
* GetCollationKey.java
* Author:-RoseIndia Team
* Date:-16-Jun-2008
*/

import java.util.*;
import java.text.*;
public class GetCollationKey {
public static void main(String[] args) {
    ArrayList list=new ArrayList();
    list.add("r");
    list.add("o");
    list.add("s");
    list.add("e");
Collator collate = Collator.getInstance();

    CollationKey[] keys = new CollationKey[list.size()];

    for (int k = 0; k < list.size(); k ++)
      keys[k] = collate.getCollationKey((String)list.get(k));

 
    for (int l= 0;l < keys.length; l++) {
      System.out.println(keys[l].getSourceString());
    }
  }
}


Output of the program:-

r
o
s
e

VelMurugan

Collator GetAvailableLocales() Example

Returns an array of all locales for which the getInstance methods of this class can return localized instances.

Collatorclass GetAvailableLocales() method example. This example shows you how to use GetAvailableLocales() method.This method Returns an array of all locales for which the getInstance methods of this class can return localized instances.

Here is the code:-

/*
* @Program that  Returns an array of all locales for which the getInstance
methods of this class can return localized instances.
* GetAvailableLocales.java
* Author:-RoseIndia Team
* Date:-16-Jun-2008
*/

import java.util.*;
import java.text.*;

public class GetAvailableLocales {

    public static void main(String[] args) {
        Collator collate = Collator.getInstance();
        Locale l[] = collate.getAvailableLocales();
        System.out.println("Locales for which the getInstance methods can return localized instances ");
        for (int i = 0; i < 15; i++) {
        System.out.println(l[i]);
        }
    }
}


Output of the program:-

QuoteLocales for which the getInstance methods can return localized instances
ja_JP
es_PE
en
ja_JP_JP
es_PA
sr_BA
mk
es_GT
ar_AE
no_NO
sq_AL
bg
ar_IQ
ar_YE
hu

VelMurugan

Collator Equals1() Example

Convenience method for comparing the equality of two strings based on this Collator's collation rules.

Collatorclass Equals1() method example. This example shows you how to use Equals1() method.This method Convenience method for comparing the equality of two strings based on this Collator's collation rules.

Here is the code:-

/*
* @Program that gives a Convenience method for comparing the equality of two strings
    based on this Collator's collation rules.
* Equals1.java
* Author:-RoseIndia Team
* Date:-16-Jun-2008
*/

import java.util.*;
import java.text.*;
public class Equals1 {
public static void main(String[] args) {
Collator collate = Collator.getInstance();
String s="erhjfkwe";
String s1="erhjfkwekgujiorj";
//Convenience method for comparing the equality of two strings
boolean b=collate.equals(s, s1);
System.out.println("Equals : "+b);
    }
}


Output of the program:-

Equals : false

VelMurugan

Collator Equals() Example

Compares the equality of two Collators.

Collatorclass Equals() method example. This example shows you how to use Equals() method.This method Compares the equality of two Collators.

Here is the code:-

/*
* @Program that Compares the equality of two Collators.
* Equals.java
* Author:-RoseIndia Team
* Date:-16-Jun-2008
*/

import java.util.*;
import java.text.*;
public class Equals {
public static void main(String[] args) {
Collator collate = Collator.getInstance(new Locale ("hdg"));
Collator collate1 = Collator.getInstance();
//Compares the equality of two Collators.
boolean b=collate.equals(collate1);
System.out.println("Collators equal: "+b);
    }
}

Output of the program:-

Collators equal: true

VelMurugan

Collator Compare1() Example

Compares the source string to the target string according to the collation rules for this Collator.

Collatorclass Compare1() method example. This example shows you how to use Compare1() method.This method Compares the source string to the target string according to the collation rules for this Collator.

Here is the code:-

/*
* @Program that Compares the source string to the target string according to
    the collation rules for this Collator.
* Compare1.java
* Author:-RoseIndia Team
* Date:-16-Jun-2008
*/

import java.util.*;
import java.text.*;
public class Compare1 {
public static void main(String[] args) {
Collator collate = Collator.getInstance();
        String s1="jhfdkjk";
        String s2="jhfdkjklrejf";
        //Compares the source string to the target string
        int i=collate.compare(s2, s1);
        System.out.println(i);
    }

}


Output of the program:-

1

VelMurugan

Collator Compare() Example

Compares its two arguments for order.

Collatorclass Compare() method example. This example shows you how to use Compare() method.This method Compares its two arguments for order.

Here is the code:-

/*
* @Program that Compares its two arguments for order.
* Compare.java
* Author:-RoseIndia Team
* Date:-16-Jun-2008
*/

import java.util.*;
import java.text.*;

public class Compare {

    public static void main(String[] args) {
        Collator collate = Collator.getInstance();
        Object s1="jhfdkjk";
        Object s2="jhfdkjklrejf";
        //Compares its two arguments for order.
        int i=collate.compare(s2, s1);
        System.out.println(i);
    }
}


Output of the program:-

1

VelMurugan

Collator Clone() Example

Returns a clone of this instance.

Collatorclass Clone() method example. This example shows you how to use Clone() method.This method Returns a clone of this instance.

Here is the code:-

/*
* @Program that returns a clone of this instance.
* Clone.java
* Author:-RoseIndia Team
* Date:-16-Jun-2008
*/
import java.util.*;
import java.text.*;
public class Clone {
public static void main(String[] args) {
Collator collate = Collator.getInstance();
Object o=collate.clone();
System.out.println("Hash Code is: "+o.hashCode());
  //Specify the  Decomposition mode value.
System.out.println("The Decomposition mode value : "+collate.FULL_DECOMPOSITION);
    }
}


Output of the program:-


The Decomposition mode value : 2