AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

ListIterator

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help
View previous topic :: View next topic  
Author Message
Québec
Guest





PostPosted: Thu Nov 27, 2003 12:59 pm    Post subject: ListIterator Reply with quote



Hi again,

Why this does not work?


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

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()Wink{
System.out.println ((String)it2.next() + "-");
/*
for(int k =0; 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 c1.add(String.valueOf(str1.charAt(k)));
for (int m = 0;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));

}
}


Back to top
Fredrik Lindner
Guest





PostPosted: Thu Nov 27, 2003 1:49 pm    Post subject: Re: ListIterator Reply with quote



Hi Québec


"Québec" <jpda (AT) vidn (DOT) ca> wrote

Quote:
Hi again,

Why this does not work?

It's quite difficult to tell when you don't inform us what the problem is.
Does the code generate an exception? If so what is the exception. Doesn't
the code work as you'd expect? Then what is it supposed to do?

Anyway, in your code I see the following statement

ListIterator it2=it.listIterator( it.size() );

shortly follwowed by

( (String) it2.next() ...

Since the Iterator is positioned just by the end of the list the it2.next()
call should cause a NoSuchElementException. Are you experiencing that or am
I misuderstanding your code?

Do provide some more details concerning your problem and I'll try to help.

/Fredrik

Quote:


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

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()Wink{
System.out.println ((String)it2.next() + "-");
/*
for(int k =0; 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 c1.add(String.valueOf(str1.charAt(k)));
for (int m = 0;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));

}
}





Back to top
VisionSet
Guest





PostPosted: Thu Nov 27, 2003 1:50 pm    Post subject: Re: ListIterator Reply with quote




"Québec" <jpda (AT) vidn (DOT) ca> wrote

Quote:
Hi again,

Why this does not work?


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

ListIterator listIterator(int index)
Returns a list iterator of the elements in this list (in proper
sequence), starting at the specified position in the list.

so it2 will be empty!

--
Mike W



Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.