问题: 出现ClassCastException
见下图 :
图片描述
程序代码如下:
import java.util.*;
import net.mindview.util.*;
class Words
{
String s ;
int i ;
public Words (String s , int i )
{
this . s = s ;
this . i = i ;
}
}
public class HoldingEx22 {
public static void main(String[] args)
{
Set words = new TreeSet(
new TextFile("SetOperations.java", "\\W+"));
System.out.println(words);
Set wordSet = new TreeSet ( ) ;
System.out.println( );
for (String s : words)
{
int count = 0;
for (String m : words)
{
if (s . equals (m) )
{
count ++ ;
}
}
Words w = new Words (s , count - 1);
wordSet . add (w ) ;
}
System.out.println(wordSet);
}
}
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
认证0级讲师