Wednesday, August 27, 2008

Java: Distinct List Function

The below java function will distinct a list of string that splitted by coma.

For example:
If input = A,A,B,B,C
This function will return A,B,C in Vector type.



Vector DistinctList(String lists){
   int a=0;
   int i=0,j=0,k=0;
   boolean dup = false;
   Vector vPreConCols = new Vector();
   String[] L1 = split(lists,",");    vPreConCols.add(L1[0]);
   a=1;
    for(i=1; i<L1.length; i++){
       j=0;
          while((j<a)&&(dup==false)){
            if(L1[i].equalsIgnoreCase(vPreConCols.get(j).toString())){
                dup=true;
            }
            j+=1;
         }
          if(!dup){
            vPreConCols.add(L1[i]);
         a+=1;
          }
   }
return vPreConCols;
}

No comments:


Since 26 July 2008: