Sequence of string to compare

Hi,
I am new to java programing...
i want to compare sequence of string .
for example :list = [1,2,3,4,5,6,7,8
and testlist =[4,5,6]
i need to compare list and testlist and the reuslt of this comprison will be true because [4,5,6] is in sequence .suppose testlist contains[ 4,7,8] it should return false as it is not in sequence with regards to the list [1,2,3,4,5,6,7,8]
i have tried using List collection....but it give the result true even if the string is not in sequence.
thanks in advance
kar

following is my code
import java.io.*;
import java.util.*;
public class compute
static int[]testpath= new int [100];
static     int t=0;
public static void main(String[] args)
int n;
String N;
int [] array;
try
     System.out.println("Enter the number of test case required");
InputStreamReader reader = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(reader);
N = br.readLine();
n=Integer.parseInt(N);
array= new int[n];
//System.out.println(+n);
System.out.println("Enter the test case");
for (int z=0;z<n;z++)
          {String num;
              num= br.readLine();
              array[z]= Integer.parseInt(num);
               //array[z]= br.read();
computeStats(array);
catch (IOException e)
e.printStackTrace();
               public static void computeStats (int [ ] numbers)
     int length = numbers.length;
     System.out.println(+length);
     double med, var, sd, mean, sum, varsum;
     sum = 0;
     System.out.println("NODE 1 INITIAL NODE numbers,sum=0,length=numbers.length");
     testpath[t]= 1;
     t++;
     System.out.println("NODE 2 i=0 for the FOR LOOP");
     testpath[t]=2;
     t++;
     for (int i = 0; i < length; i++)
     {System.out.println("NODE 3 DUMMY NODE ");
          testpath[t]=3;
     t++;
     System.out.println("NODE 4 SUM+=NUMBERS[i] AND i++");
     testpath[t]=4;
     t++;
     sum += numbers [ i ];
     System.out.println("NODE 3 DUMMY NODE ");
     testpath[t]=3;
     t++;
     System.out.println("NODE 5 MED,MEAN,VARSUM,i=0");
     testpath[t]=5;
     t++;
     med = numbers [ length / 2 ];
     mean = sum / (double) length;
     varsum = 0;
     for (int i = 0; i < length; i++)
     {System.out.println("NODE 6 DUMMY NODE");
          testpath[t]=6;
     t++;
     System.out.println("NODE 7 VARSUM CALCULATION");
     testpath[t]=7;
     t++;
     varsum = varsum + ((numbers [ i] - mean) * (numbers [ i ] - mean));
     System.out.println("NODE 6 DUMMY NODE");
     testpath[t]=6;
     t++;
     System.out.println("NODE 8 END PART FINAL NODE ");
     testpath[t]=8;
     t++;
     var = varsum / ( length - 1.0 );
     sd = Math.sqrt ( var );
     System.out.print("testpath followed");
     String testpathstr[]= new String[t];
for(int y=0;y<t;y++)
testpathstr[y]= Integer.toString(testpath[y]);
List pathlist= Arrays.asList(testpathstr);
//String pathlist= Arrays.toString(testpathstr);
System.out.println(pathlist);
boolean Choice;
Choice = true;
String Count;
int count=0 ;
System.out.println("Enter the number of Du path");
try{
     InputStreamReader reader = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(reader);
Count= br.readLine();
count=Integer.parseInt(Count);
System.out.println(+count);
catch (IOException e)
e.printStackTrace();
int i=0;
while(i<=count)
System.out.println("enter the len of Du-path u wanna test");
try{
     InputStreamReader reader = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(reader);
String lengt= br.readLine();
int len = Integer.parseInt(lengt);
String dupath[] = new String[len];
for(int a=0;a<len;a++)
     dupath[a]= br.readLine();
     System.out.println(dupath[a]);
     List dupathlist= Arrays.asList(dupath);
     System.out.println(dupathlist);
     String x;
     int xy;
     //xy=pathlist.compareTo(dupathlist);
     //x= Integer.parseInt(s)
     //System.out.println(+xy);
//String visited = new ArrayList(pathlist);
     boolean is ;
     is = pathlist.containsAll(dupathlist);// this what i am doing....path list contains set of numbers and i compare it with dupathlist     
System.out.println(is);
     if(is)
          System.out.println("dupath visited");
     else
          System.out.println("dupath not visited");
//     System.out.println(visited);
     System.out.println("Do you want to test another dupath(Yes or no)");
     String choice;
     choice= br.readLine();
     String yes="yes";
     System.out.println(choice);
     if(choice.equals(yes))
          i++;
          System.out.println(choice);
     else
          break;
catch (IOException e)
e.printStackTrace();
     // System.out.println ("length: " + length);
     // System.out.println ("mean: " + mean);
     // System.out.println ("median: " + med);
     // System.out.println ("variance: " + var);
     // System.out.println ("standard deviation: " + sd);
}

Similar Messages

  • Can we use sequences with strings?

    In Sql can we use sequence with strings? ......please tel me

    Hi,
    Sorry, sequences only generate numbers.
    You could write a function in PL/SQL which generates a string, based on the value it gets from a sequence.
    Edited by: Frank Kulash on Jan 22, 2009 2:31 PM
    Of course, you can convert the number to a string, like Salim demonstrated. I assume you're talking about something that generates, for example, 'A', 'B', ..., 'Z', 'AA', 'BB', ..., 'ZZ', 'AAA', ...

  • Regular expression to check the sequence of strings

    HI,
    I am validating an EDI document like as follows
    ISA*XX*XXXXXXXXXXXXXXX*XX*XXXXXXXXXXXXXXX*030130*0912*~IEA*1*000005900~
    I need to create a regular expression which checks ISA should always occur before IEA.
    Please help me if you have any hints.
    Thanks.

    Thanks.I had taken that into consideration.
    But using regular expression I could say
    ISA* only once
    IEA* only once
    And
    ISA before IEA
    Any hints how to specify "before"/sequence using Regular expression ?
    I agree sometime using basic String operation we can do this.

  • Autoincrement Sequence with String and number

    Hi,
    I have a db for a small company where there are different kinds of employees.
    As a primary key of each table (for each type of employee), I would like to have a combination of a string and integer.
    e.g. if the employee is a car mechanic then the primary key should be something like: CM001, CM002, ....
    if the employee is from the it department then the primary key should be like: IT001, IT002, ....
    I have found a few script for sequences and triggers to use the auto-increment, but I could not find anything about concatenating a string in front of the integer.
    any help appreciated.
    thanks

    user5205421 wrote:
    As a primary key of each table (for each type of employee), I would like to have a combination of a string and integer.You really don't want to have a combined column in your tables, and certainly not as a primary key.
    If you use a combined column you'll find your are uncombining the column all over your application using substr's, index usage will not be trivial anymore, people can't change from departments anymore since primary keys can never change. You are just asking for trouble. When your customer says that that's the number/code they want to see and with which they identify themselves, that doesn't mean you need to implement it as a primary key.
    My advice:
    - create an ID column with a primary key constraint and fill it using a sequence.
    - have a department code column, optionally a foreign key to a table with departments
    - use: department_code || to_char(id,'fm000') or department_code || row_number() over (partition by department_code order by id), only for display reasons in your applications, possibly in a view.
    Regards,
    Rob.

  • Re: PLS-00357 Table,View Or Sequence reference 'string' not allowed in this con

    i have the same problem , can somebod help
    i pasting my code here , please help me resolving
    SQL> declare
      2  continue char(1):='y';
      3   begin
      4  while(continue='y')
      5  loop
      6  dbms_output.put_line('somen');
      7  dbms_output.put_line('do u wan continue');
      8  continue:=to_char(&continue);
      9  end loop;
    10  end;
    11  /
    Enter value for continue: y
    old   8: continue:=to_char(&continue);
    new   8: continue:=to_char(y);
    continue:=to_char(y);
    ERROR at line 8:
    ORA-06550: line 8, column 19:
    PLS-00357: Table,View Or Sequence reference 'Y' not allowed in this context
    ORA-06550: line 8, column 1:
    PL/SQL: Statement ignored

    Just to emphasise Sven's point that the substitution variable (&continue) is resolved once and "compiled" into the code, try making a stored procedure instead of an anonymous block.
    SQL> create procedure p as
      2     continue char(1):='y';
      3  begin
      4     while(continue='y') loop
      5        dbms_output.put_line('somen');
      6        dbms_output.put_line('do u wan continue');
      7        continue:=('&continue');
      8     end loop;
      9  end;
    10  /
    Enter value for continue: q
    old   7:       continue:=('&continue');
    new   7:       continue:=('q');
    Procedure created.
    SQL> select text from user_source
      2  where name = 'P'
      3  order by line;
    TEXT
    procedure p as
       continue char(1):='y';
    begin
       while(continue='y') loop
          dbms_output.put_line('somen');
          dbms_output.put_line('do u wan continue');
          continue:=('q');
       end loop;
    end;
    Note that where you had the substitution variable, there is now a literal value, q in my case.  Note that because I did not respond with y for the value of continue I can safely run this procedure.
    SQL> exec p;
    somen
    do u wan continue
    PL/SQL procedure successfully completed.
    John

  • Comparing char in a string to strings in a txt file

    Hi guys, i am dveloping a scrabble application for a project in jvava. Currently, i am trying to work on coding a computer player to play against a human, ive finished all the game logic nd 2 human players can successfully play on the same system.
    My problem is when coming up with the AI logic, i am faced with the problem of how to compare the computer player's letters to the dictionary txt file in order to find the possible words he can play.
    For example, the PC player has the letters A,B,E,G,T,F in his rack, it searches the dictionary and finds words that also contain these characters, so it would return words like AT, BAT, GATE, etc. I have already looke up the Jumble algorithm, but i dont really understand it(im still quite new to java).
    I already have a ditionary class which i put the code below.
    What i want to do now is just to come up with a simple method that takes a string, and compares the chars, and find words that match the char and return them but i dont knw hw to come about it.
    import java.util.Scanner;      
    import java.io.IOException;  
    import java.util.ArrayList;   
    import java.io.*;             
    public class Dictionary
        ArrayList<String> dictionary;
        public Dictionary() throws IOException
            dictionary = new ArrayList<String>();
        public void readInDictionaryWords() throws IOException
            File dictionaryFile = new File("c:/data/dict.txt");    // declare the file
            if( ! dictionaryFile.exists()) {
                System.out.println("*** Error *** \n" +
                                   "Your dictionary file has the wrong name or is " +
                                   "in the wrong directory.  \n" +
                                   "Aborting program...\n\n");
                System.exit( -1);    // Terminate the program
            Scanner inputFile = new Scanner( dictionaryFile);
            while( inputFile.hasNext()) {
                dictionary.add( inputFile.nextLine().toUpperCase() );
        public boolean wordExists( String wordToLookup)
            if( dictionary.contains( wordToLookup)) {
                return true;    // words was found in dictionary
            else {
                return false;   // word was not found in dictionary
        return"";
    }

    Loops...
    You take the first
    then second
    then third
    and etc
    You take the first 2
    the next 2
    the next 2
    etc
    all the way through n characters
    once you have gone through this, then you have to do all possible combinations of characters of 2 through n.
    Here is an implementation of N choose k for k up to 7:
    public class Junk {
      public Junk(){
      public void choose1(String s){
        int lCount=0;
        for(int i=0; i<s.length(); i++){
          System.out.println("("+s.charAt(i)+")");
          lCount++;
        System.out.println("Distinct Combinations: "+lCount);
      public void choose2(String s){
        int lCount=0;
        for(int i=0; i<s.length(); i++){
          for(int j=i+1; j<s.length(); j++){
              System.out.println("("+s.charAt(i)+", "+s.charAt(j)+")");
              lCount++;
        System.out.println("Distinct Combinations: "+lCount);
      public void choose3(String s){
        int lCount=0;
        for(int i=0; i<s.length(); i++){
          for(int j=i+1; j<s.length(); j++){
            for(int k=j+1; k<s.length(); k++){
              System.out.println("("+s.charAt(i)+", "+s.charAt(j)+", "+s.charAt(k)+")");
              lCount++;
        System.out.println("Distinct Combinations: "+lCount);
      public void choose4(String s){
        int lCount=0;
        for(int i=0; i<s.length(); i++){
          for(int j=i+1; j<s.length(); j++){
            for(int k=j+1; k<s.length(); k++){
              for(int l=k+1; l<s.length(); l++){
                System.out.println("("+s.charAt(i)+", "+s.charAt(j)+", "+s.charAt(k)+", "+s.charAt(l)+")");
                lCount++;
        System.out.println("Distinct Combinations: "+lCount);
      public void choose5(String s){
        int lCount=0;
        for(int i=0; i<s.length(); i++){
          for(int j=i+1; j<s.length(); j++){
            for(int k=j+1; k<s.length(); k++){
              for(int l=k+1; l<s.length(); l++){
                for(int m=l+1; m<s.length(); m++){
                  System.out.println("("+s.charAt(i)+", "+s.charAt(j)+", "+s.charAt(k)+", "+s.charAt(l)+", "+s.charAt(m)+")");
                  lCount++;
        System.out.println("Distinct Combinations: "+lCount);
      public void choose6(String s){
        int lCount=0;
        for(int i=0; i<s.length(); i++){
          for(int j=i+1; j<s.length(); j++){
            for(int k=j+1; k<s.length(); k++){
              for(int l=k+1; l<s.length(); l++){
                for(int m=l+1; m<s.length(); m++){
                  for(int n=m+1;n<s.length(); n++){
                    System.out.println("("+s.charAt(i)+", "+s.charAt(j)+", "+s.charAt(k)+", "+s.charAt(l)+", "+s.charAt(m)+", "+s.charAt(n)+")");
                    lCount++;
        System.out.println("Distinct Combinations: "+lCount);
      public void choose7(String s){
        int lCount=0;
        for(int i=0; i<s.length(); i++){
          for(int j=i+1; j<s.length(); j++){
            for(int k=j+1; k<s.length(); k++){
              for(int l=k+1; l<s.length(); l++){
                for(int m=l+1; m<s.length(); m++){
                  for(int n=m+1; n<s.length(); n++){
                    for(int o=n+1; o<s.length(); o++){
                      System.out.println("("+s.charAt(i)+", "+s.charAt(j)+", "+s.charAt(k)+", "+s.charAt(l)+", "+s.charAt(m)+", "+s.charAt(n)+", "+s.charAt(o)+")");
                      lCount++;
        System.out.println("Distinct Combinations: "+lCount);
      public static void main(String[] args) {
        Junk j = new Junk();
        j.choose7("1234567");
    }I'll leave it to you to integerate the algos into your app appropriately.

  • How to compare 2 version strings (of the format x.x.x.x where x : {0, 99})

    I am using Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production,
    PL/SQL Release 11.2.0.2.0 - Production
    I have a scenario like:
    Table1:
    Name Null Type
    NAME NOT NULL VARCHAR2(64)
    VERSION NOT NULL VARCHAR2(64)
    Data:
    Table1
    Name Version
    A 1
    B 12.1.0.2
    B 8.2.1.2
    B 12.0.0
    C 11.1.2
    C 11.01.05
    I want the output as:
    Name Version
    A 1
    B 12.1.0.2
    C 11.01.05
    Basically ,I want to get rows for each name which having highest version. For this i am using following query:
    SELECT t1.NAME,
    t1.VERSION
    FROM TABLE1 t1
    LEFT OUTER JOIN TABLE1 t2
    on (t1.NAME = t2.NAME and t1.VERSION < t2.VERSION)
    where t2.NAME is null
    Now 't1.VERSION < t2.VERSION' only works in normal version cases but in cases such as:
    B 12.1.0.2
    B 8.2.1.2
    It fails, So i want a PL/SQL script to normalize the version strings and compare them for higher value.

    Hi,
    Here's one way:
    ORDER BY  REGEXP_REPLACE ( REGEXP_REPLACE  ( version
                                           , '(\d+)'
                                , '0000\1'
                    , '0+(\d{5})'
                    , '\1'
                    )This assumes that you never have more than 5 digits in a row. You can easily change that to any fixed number.
    This will not cause an error if you have letters or other symbols in the string.
    This makes no assumptions about how many numbers are in the string, or what characters delimit the numbers.
    Here's how it works:
    The inner REGEXP_REPLACE adds 4 '0's immediately before any substring of digits. This guarantees that all numbers are at least 5 digits long.
    The outer REGEXP_REPLACE removes '0's from the beginning of numbers that are more than 5 digits long, which guaranteees that the numbers will be exactly 5 digits long. '00008' will come before '00012'

  • Where the string "failed" is created in steps in the main sequence to fill into Parameter.Result PostUUT in the NI teststand II courese example 4-1 Modifying callback.seq

    For PostUUT in  the NI teststand II  courese example 4-1 Modifying callback.seq, there are two steps, one is Test Passed,
    the other is Test Failed, both set each preconditions, for example, Parameters.Result.Status == "Failed"  in the test failed step, if the step failed in the main sequence,the string "failed " is filled into Parameters.Result.Status
     but I can't find where the string "failed" is created in steps in the main sequence. 
     Because I can't find any expression in any steps  to fill into Parameters.Result of  the test failed step in the PostUUT. 
    In fact, when running if step fails, the string "failed " is filled into Parameters.Result.Status 
     Would you please  explain for it ? 
    thanks,

    Hi,
    Look at the Sequential Model Sequence File, and either the sequence SinglePass of Test UUTs for the step that invokes the step Post UUT.
    Then look at the Parameter List for the SequenceCall for that step. you will find your answer.
    Regards
    Ray Farmer

  • Compare two strings for partial or full match

    I have been trying to figure out away of comparing two strings.
    I can get the full string matching to successfully work but am struggling on how to get partial eg wildcard search working.
    say I had names like paul Duncan, George Morrison.
    I have split them up so its now paul , duncan i then use the users entered string to compare it against the name name to see if it matches anything in the first name or the last name if it does i added it to an arraylist.
    however i have tried t use a indexof as i believe this looks for similarity (Substring matches?) but it always returns -1.
    Could anyone possibly direct me to a method that will allow me to use partial text string to match it against stored user names.
    eg user enters pa
    I would return anything that would contain pa
    thanks for any help

    thank you for the reply
    Sorry I forgot to put in the code.
    This is a reduced down version including the read in from a text file as well as the index of if statement and the adding of it to an array list.
    public class FindContact {
    String res;
    /** Creates a new instance of FindContact */
    public FindContact() {
    public Object[] FindAUser(String passSearch) {
    System.out.println("getting here");
    ArrayList found = new ArrayList();
    String patternStr = ",";
    int j, i = 0;
    try {
    BufferedReader in = new BufferedReader(new FileReader("H:\\out.txt"));
    String str;
    while ((str = in.readLine()) != null) {
    String[] fields = str.split(patternStr);
    //for(j=0;j < fields.length;j++) {
    if (fields.length != 0) {
    if (passSearch.indexOf(fields[0])!=-1 || passSearch.indexOf(fields[1])!=-1) {
    found.add(str);
    System.out.println("ENDDDDDDDD value ");
    in.close();
    } catch (IOException e) {
    System.out.println(e.toString());
    Object[] foundResult = new Object[found.size()];
    foundResult = found.toArray();
    if (foundResult.length >= 0) {
    System.out.println(foundResult.length);
    return foundResult;
    Hope that helps as it has confused me and am not sure why it is not returning a value.
    Should I maybe use the contain method instead to search for the user inputted string?

  • Comparing two strings

    How do you check to see if two strings have dashes in the same places?
    For example:
    String one= "dfsdt-ra-s-dsfd";
    String two= "dsfst-da-s-dsfd";
    would return true.
    String one="jhsdjfk-dsf-sdf"
    String two="d-dsf-dfsf-f"
    would return false.
    This is what i have:
    if (one.indexOf("-") == two.indexOf("-")) {
    return true;
    The problem with this if statement is it only checks the first time the dash come and not the whole string.
    How can I check the whole string to compare the index of string one and string two every time the dash come up.

    Hey,
    Check this code out, compile it and you should get it. Let me know if you have any questions.
    Thanks
    Riz
    public class StringCheck {
         String s1;
         String s2;
         boolean AreEqual;
         int lens1,lens2;
         public StringCheck(){
              s1="dfsdt-ra-s";
              s2="dfsdt-ra-s";
              AreEqual=false;
              lens1=s1.length();
              lens2=s2.length();
         public boolean CheckTheString(){
              boolean localcheck=false;
              if(lens1==lens2){
                   for(int i=0;i<lens1;i++){
                        if(s1.charAt(i)==s2.charAt(i)){
                             localcheck=true;
                             i++;
                        if(s1.charAt(i)!=s2.charAt(i)){
                             return false;
              if(localcheck)return true;
              else return false;
              //return true;
         public static void main(String args[]){
              StringCheck c = new StringCheck();
              boolean validate=c.CheckTheString();
              if(validate)
                   System.out.println("The string are equal");
              else
                   System.out.println("The String are not equal");
    }

  • Any lib for wildcast String compare

    Hallo,
    Is there any lib supporting String wildcast compare? as filename style in DOS or unix, "files*", "files??To compare".

    http://jakarta.apache.org/oro/index.html

  • How to execute contain operation in sequences?

    Hi,I am confused about sequences,it seems java.util.Collection more convenient,so why need sequences.
    and how can I do a contain operation on sequences?if use indexof operator,how to determin object equals?how to implements equals method in javafx object?

    One way to determine whether or not a Sequence contains an element is to implement a Comparator (or have the element implement Comparable) and use the javafx.util.Sequences.binarySearch function.
    I don't have access to a compiler at the moment, but something like this should work:
    import javafx.util.Sequences;
    var strings: String[] = [
            "Hello",
            "World",
            "Goodbye"
    //Sequence needs to be sorted for us to be able to determine whether or not it contains a given string with a binary search. String already implements Comparable, so we do not need to use a comparator.
    strings = Sequences.sort(strings);
    //Now determine whether or not this sequence contains the specified string.
    var containsString: Boolean = (Sequences.binarySearch(strings, "Hello") != -1); //This should return true.I haven't tried overriding equals, but I've overridden toString() just fine, so you can probably do that in a similar way:
    public class MidiInstrument {
        public-init var name: String;
        public-init var bank: Integer;
        public-init var program: Integer;
         * Overrides toString to ensure that the ChoiceBox used to choose an instrument can display this item as a string.
        public override function toString(): String {
            return name;
    }

  • String equal method Vs Object equal method.

    hello, Can anybody explain me difference between equal method in String class and equal method in Object class. We have equal method in object classes. and object class is the super class of all classes, so why we need equal method in String class.

    RGEO wrote:
    hello, Can anybody explain me difference between equal method in String class and equal method in Object class. We have equal method in object classes. and object class is the super class of all classes, so why we need equal method in String class.Because "equal" means different things for different objects. For a String, "equal" would mean that both Strings being compared have the exact same characters, in the same sequence. For an Integer, "equals" would mean that both objects have the same integer value.

  • Treeset.contains(String) is case sensitive ?

    hi
    i noticed that treeset.contains(String) is case sensitive.
    when you all are testing keywords do you therefore put everything to lower case to test ?
    just double checking something extremely simple

    Well strings are case sensitive. Try using String.equalsIgnoreCase(String) to compare strings without regards to case. As for using it in collections, you may want to convert all strings to upper or lower case before placing them into collections (this may not always be possible due to "business reasons").
    Note: contains(String) on the Collection interface uses Object.equals(Object o) to test object equality. The implentation of equals on String will return true if and only if the argument is not null and is a String object that represents the same sequence of characters as this object. Case will not be ignored in this implementation.
    Hope this helps.

  • Collator compare doubt

    I am using the java collator compare to sort strings alphabetically.
    The input strings are:
    1)Google home Page
    2)Yahoo Home page
    3)orkut Home Page
    After this the lines are circulary shifted and then sorted.
    After sorting i am getting the following output.
    Google home Page
    home Page Google
    Home Page orkut
    Home page Yahoo
    orkut Home Page
    Page Google home
    Page orkut Home
    page Yahoo Home
    Yahoo Home page
    Shouldn't p become before P?
    My understanding is that collator compare does a natural language comparator. So it should sort like a<A<b<B<c<C........z<Z
    (i.e a less than A less than b less than B...)
    The comparator i am using is
    Collections.sort(arrayList,new Comparator() {
    public int compare(Object o1, Object o2)
    Collator myCollator = Collator.getInstance();
    myCollator.setStrength(Collator.TERTIARY);
    String str1 = (String)o1.toString();
    String str2 = (String)o2.toString();
    return myCollator.compare(str1,str2);
    Is there anything wrong in the way I am using the comparator or is my understanding of the way collator works is wrong?
    I tried setting the locale also..but no difference.
    Message was edited by:
    n.santhosh

    Read the How Should I Compare String Objects tip for information on how a
    Collator works.The statement made there that alphabetic differences are "primary" is what I
    was getting at. The OP's output is exactly what you would expect from an
    alphabetic ordering of strings.
    But the OP wants
    page Yahoo Home < Page Google Home
    notwithstanding the fact that Y > G.
    It looks like the wrong things are being compared. Instead of comparing
    strings (sequences of letters - I realise Collator doesn't exactly do that),
    phrases (sequences of strings) should be compared. Something along
    the lines ofstatic int comparePhrase(List<String> phr1, List<String> phr2) {
        int sz1 = phr1.size();
        int sz2 = phr2.size();
        if(sz1 == 0 && sz2 == 0) return 0;
        if(sz1 == 0) return -1;
        if(sz2 == 0) return 1;
            // coll is a Collator instance
        int ret = coll.compare(phr1.get(0), phr2.get(0));
        if(ret != 0) return ret;
        return comparePhrase(phr1.subList(1, sz1), phr2.subList(1, sz2));
    }

Maybe you are looking for

  • SSRS Matrix Report

    Please see below matrix report before and after I run. How can I find percentage of below marked fields, for example: 1/3=0.33 (%33)  Female(PAs)/Total(PAs)=? Erdal Huzmeli

  • AS3 Flash Chat(-IRC) Module

    Over the past I had create in AS2 a chat application, where after a registration the users could enter the application and talk together like an IRC application. Still it was very novice, as I used a mySQL database to keep the messages, and I was upd

  • What is unique in ABAP which is not in other oops languages?

    What is unique in ABAP which is not in other oops languages?

  • Ipad has new message "no simm card"

    My ipad inexplicably said "no Sim" The cellular data which I normally get, is no longer registering. There has been no change to my Sim card, which remains in place as usual. My wifi access continues to work, just no cellular data access. There were

  • [Discover] Not discovering anything

    Dear all, I did a fresh install on my windows 7 machine, of Spotify 1.0.7`.7157. While playing music I was expecting the Discover feature to load up suggestions, but it remains at the initial message: "Play something you love [etc]..." How do I make