ListIterator

From: Québec (jpda_at_vidn.ca)
Date: 11/27/03


Date: Thu, 27 Nov 2003 07:59:39 -0500


    Hi again,

                        Why this does not work?

for (ListIterator it2=it.listIterator(it.size()); it2.hasNext();){

   System.out.println (it2.next() + "-");
  /*
  for(int k =0; k<vow.length;k++){
   if(it2.next().equals(vow[0])){
   it2.previous();
   it2.remove();
   it2.next();
   it2.remove();
   it2.next();
   it2.remove();
   }
  }
  */
 }

Jean
===================================

import java.util.*;

public class MyCollection{

 public static void print(Collection it){
    Iterator it2 = it.iterator();
 System.out.println();
    while(it2.hasNext())
      System.out.print(it2.next());
 System.out.println();
 }

 public static void vowels(List it){
 String[] vow = {"a", "â", "ä", "à", "e", "ê", "é", "è", "ë", "i", "î", "ï",
"o", "ô", "ö", "u", "û", "ü"};
    for (ListIterator it2=it.listIterator(it.size()); it2.hasNext();){
   System.out.println ((String)it2.next() + "-");
  /*
  for(int k =0; k<vow.length;k++){
   if(it2.next().equals(vow[0])){
   it2.previous();
   it2.remove();
   it2.next();
   it2.remove();
   it2.next();
   it2.remove();
   }
  }
  */
 }
 System.out.println("The End");
 }

 public double comp(String str1, String str2){

 int len1 = str1.length();
 int len2 = str2.length();

 int len = (len1 > len2) ? len1 : len2;

 List c1 = new ArrayList();
 Collection c2 = new ArrayList();
 //Collection c3 = Arrays.asList(str1.toCharArray());
  for (int k = 0;k<len1; k++)
   c1.add(String.valueOf(str1.charAt(k)));
  for (int m = 0;m<len2; m++)
   c2.add(String.valueOf(str2.charAt(m)));

 List smallest = new ArrayList();
 /*
 Collections.sort(c1);
 print(c1);

 Collections.shuffle(c1);
 print(c1);
 */

 if(len1 < len2){
  c2.retainAll(c1);
  smallest = (List)c1;
 }else{
  c1.retainAll(c2);
  smallest = (List)c2;
 }

 print (smallest);
 vowels (smallest);
 print (smallest);
 return ((double)smallest.size()/(double)len);
 }

  public static void main(String[] args) {

 String str3 = "the_miseducation_of_lauryn_hill";
 String str4 = "ms edcation oflaryn hill";
 System.out.println("\n" + new MyCollection().comp(str3, str4));

  }
}