我试图从URL中提取标题和元标记的描述内容,这就是我所拥有的:
fin[] //urls in a string array
for (int f = 0; f < fin.length; f++)
{
Document finaldoc = Jsoup.connect(fin[f]).get(); //fin[f] contains url at each instance
Elements finallink1 = finaldoc.select("title");
out.println(finallink1);
Elements finallink2 = finaldoc.select("meta");
out.println(finallink2.attr("name"));
out.println(fin[f]); //printing url at last
}
Run Code Online (Sandbox Code Playgroud)
但它不打印标题,只是将描述打印为"描述"并打印网址.
结果:
description
plus.google.com
generator
en.wikipedia.org/wiki/google
description
earth.google.com
我正在尝试理解java通用的covariancy,我理解为什么
List<Number> list = new ArrayList<Integer>();
Integer = list.get(0);
Run Code Online (Sandbox Code Playgroud)
不允许使用float,因此不会将float放入列表中,从而导致问题.我相信类型擦除会将其编译为:
List list = new ArrayList();
Integer = (Integer) list.get(0);
Run Code Online (Sandbox Code Playgroud)
这是允许的:
List<? extends Number> list = new ArrayList<Integer>();
Integer = list.get(0);
Run Code Online (Sandbox Code Playgroud)
类型擦除后,这不会编译成同样的东西吗?通配符如何帮助编译器强制执行浮点数在保存整数时不会放入列表中?
第二个论点如何运作strtol?
这是我尝试过的:
strtol(str, &ptr, 10)
Run Code Online (Sandbox Code Playgroud)
其中ptr是 achar *并且str是一个字符串。现在,如果我传入stras'34EF'和 print *ptr,它会正确地给我E, 并*(ptr+1)给我F,但是如果我 print ptr,它会给我EF!打印不应该ptr导致像十六进制地址之类的垃圾值吗?
为什么这两段代码产生不同的输出?
$a = 3;
($a == 4) and print "But I wanted apple, cherry, or blueberry!\n" ;
Run Code Online (Sandbox Code Playgroud)
没有节目输出但是
$a = 3;
print "But I wanted apple, cherry, or blueberry!\n" and ($a == 4);
Run Code Online (Sandbox Code Playgroud)
给:但我想要苹果,樱桃或蓝莓!
我读到gprof(函数分析)和其他分析方法可以返回执行程序时发生的浮点运算的数量,因此想知道Flops如何比常规运算贵得多?
我有一个函数列表,所有这些函数都扩展了Consumer接口.我需要提取出函数的索引.这样做的原因是我正在实现循环工作流,其中用户按顺序调用列表中的函数.因此,当用户使用foo完成时,foo调用一个调度程序函数,该函数在列表中的foo之后调度该函数.为此,foo需要知道列表中自己的索引.我不想硬编码数字,这就是我试图检索foo索引的原因.这就是我所拥有的:
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.function.Consumer;
public class Experiment {
private List<Consumer<String>> activities = ImmutableList.of(
this::bar,
this::foo
);
public void bar(String x) {
System.out.println();
}
public void foo(String x) {
System.out.println();
}
public void print() {
System.out.println(activities.indexOf((Consumer<String>)this::foo));
}
public static void main(String []args) {
Experiment e = new Experiment();
e.print();
}
}
Run Code Online (Sandbox Code Playgroud)
这打印-1给我,所以它无法在列表中找到它.有没有办法从这个列表中提取出函数的索引?
我正在玩混合图像,并希望使用高斯滤波器对图像进行低通滤波.然而,为了制作混合图像,假设在2个图像上使用2个滤波器与不同的截止频率组合.
fspecial()当我们用它来制作高斯滤波器时,是否允许我们指定截止频率?(我知道我们可以指定滤波器大小和sigma,并且sigma和截止频率之间存在某种关系).如果我们只能使用sigma指定截止频率,那么我需要设置什么sigma来获得0.2 Hz的截止频率.
我有一个看起来像的文件
1::12::33::1555
1::412::1245::23444
Run Code Online (Sandbox Code Playgroud)
等等.我需要摆脱最后一个参数,并用逗号替换冒号.我试过了:
myfile = open('words.txt', 'r')
content = myfile.read()
content = re.sub(r'(.+)::(.+)::(.+)::(.+)', "\1,\2,\3", content)
myfile = open('words.txt', 'w')
myfile.write(content)
# Close the file
myfile.close()
Run Code Online (Sandbox Code Playgroud)
但后面的引用不起作用,我最后得到一个带逗号的文件.
我希望实现的目标是:
1,12,33
1,412,1245
Run Code Online (Sandbox Code Playgroud) 我已经看过这里,它适用于包含Runnables的参数减少方法列表.我需要Consumer在我的情况下.这是我到目前为止:
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.function.Consumer;
public class experiment {
private static List<Consumer<String>> activities;
public experiment (){
activities = ImmutableList.of(
(userId) -> this::bar, // throws error
(userId) -> this::foo);
}
public void bar(String x) {
System.out.println(x);
}
public void foo(String x) {
System.out.println(x);
}
public static void main(String []args) {
for (int i=0; i<2; i++) {
activities.get(i).accept("activity #" + i);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我看到的错误是void is not a functional interface.
我不明白为什么我会这样做,bar并foo …
我正在尝试为我的应用弹出一个弹出窗口。到目前为止,弹出窗口以固定的坐标弹出,我试图将其弹出到用户点击的位置。这就是我所拥有的:
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
print("touchesbegan")
for touch in touches{
//Handle touch
let location = touch.locationInView(self.view)
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("ColonyPopoverController") as! ColonyPopoverController
vc.modalPresentationStyle = .Popover
vc.preferredContentSize = CGSizeMake(200, 150)
if let popoverController = vc.popoverPresentationController {
popoverController.delegate = self
popoverController.sourceRect = CGRectMake(location.x, location.y, 20, 10)
popoverController.sourceView = self.view
self.presentViewController(vc, animated: true, completion: nil)
}
}
}
Run Code Online (Sandbox Code Playgroud)
我注意到当我点击模拟器时,打印语句永远不会打印。
我认为interaction并已multi-touch启用。我知道这种方法很好用,因为我也将其与Google Maps集成在一起,因此当我点击时,会出现一个google pin:
func mapView(mapView: GMSMapView!, didTapAtCoordinate coordinate: CLLocationCoordinate2D) …Run Code Online (Sandbox Code Playgroud) java ×4
c++ ×1
covariance ×1
flops ×1
gaussian ×1
gmsmapview ×1
java-8 ×1
jsoup ×1
matlab ×1
parsing ×1
perl ×1
profiling ×1
python ×1
regex ×1
string ×1
strtol ×1
swift ×1
touchesbegan ×1
type-erasure ×1
url ×1