这很奇怪:A是一个集合而B是一组集合:
Set <String> A=new HashSet<String>();
Set <Set<String>> B=new HashSet<Set<String>>();
Run Code Online (Sandbox Code Playgroud)
我向他们添加了东西和输出
System.out.println(A)
Run Code Online (Sandbox Code Playgroud)
是:
[evacuated, leave, prepc_behind]
Run Code Online (Sandbox Code Playgroud)
和的输出
System.out.println(B)
Run Code Online (Sandbox Code Playgroud)
是:
[[leave, to, aux], [auxpass, were, forced], [leave, evacuated, prepc_behind]]
Run Code Online (Sandbox Code Playgroud)
可以看出,集合B的第三个元素等于设定A.所以假设
if(B.contains(A)){...}
Run Code Online (Sandbox Code Playgroud)
应该返回true,但显然它不会.问题是什么?
更多细节:
Pattern pattern = Pattern.compile("(.*?)\\((.*?)\\-\\d+,(.*?)\\-\\d+\\).*");
for (int i = 0; i < list.size(); i++) {
Set <String> tp = new HashSet<String>();
Matcher m = pattern.matcher(list.get(i).toString());
if (m.find()) {
tp.add(m.group(1).toLowerCase());
tp.add(m.group(2).toLowerCase());
tp.add(m.group(3).toLowerCase());
}
B.add(tp);
}
Set <String> A=new HashSet<String>();
A.add("leave");
A.add("evacuated");
A.add("prepc_behind");
System.out.println(A);
if(B.contains(A)){
System.out.println("B contains A");
}
Run Code Online (Sandbox Code Playgroud) 我有一个问题NoClassDefFoundError.我正在使用接口,并且不应该有类定义:
package code;
public interface Constants {...}
Run Code Online (Sandbox Code Playgroud)
实现此接口的类编译时没有任何错误,并且已经构建了一个JAR文件,但在运行时它给了我一个错误.
import ...;
import code.*;
public class MultiDoc extends LanguageAnalyser implements Constants{}
Run Code Online (Sandbox Code Playgroud)
Constants 仅包含常量列表.
我读了一些指向CLASSPATH的帖子是导致这个问题的原因,但是我code在CLASSPATH中有了这个包.如果我没有它,它将产生编译错误.所以,问题应该是别的.
运行时错误是:
java.lang.NoClassDefFoundError: code/Constants
Run Code Online (Sandbox Code Playgroud)
解决方案是什么?
我正在使用此代码使用谷歌对单词列表进行查询,并从谷歌中提取搜索结果的数量.它工作正常,但自从昨晚它在执行200次查询后不断给我这个错误(我猜google标记了我!):线程"main"中的异常java.io.IOException:服务器返回HTTP响应代码:503为URL:http ://www.google.com/sorry/?continue = http://www.google.com/ ...
"红色"只是一个例子.
public class Google {
public static void main(String[] args) throws IOException {
String query = "red";
String urlName = "http://www.google.com/search?q=\""+query+"\"";
URL url = new URL(urlName);
URLConnection conn = url.openConnection();
conn.setRequestProperty("User-Agent",
"Mozilla/5.0 (X11; U; Linux x86_64; en-GB; rv:1.8.1.6) Gecko/20070723 Iceweasel/2.0.0.6 (Debian-2.0.0.6-0etch1)");
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
Pattern pattern = Pattern.compile("<div>About (.*?) results</div>"); //<div>About 1,620,000 results</div>
String line;
while ((line = in.readLine()) != null) {
Matcher m = pattern.matcher(line);
if (m.find()) {
System.out.println(m.group(1)); // …Run Code Online (Sandbox Code Playgroud)