我想要一个按集合大小排序的SortedSet集合(在这种情况下设置自己,但不一定是一般).这似乎违反了使比较器与equals()一致的禁止 - 即两个集合可能不相等(通过具有不同的元素),但是与相同的值相比(因为它们具有相同数量的元素).
从理论上讲,我也可以通过比较器的方式对相同大小的组进行排序,但是使用排序不会利用这一点,并且没有真正有用的+直观的方法来比较相同大小的集合(至少,在我的特定情况下),所以这似乎是一种浪费.
这种不一致的情况是否有问题?
我想以二维方式绘制点(每个都有x和y坐标).我想知道你是否知道这样做的库或项目,所以我不必从头开始构建它.
我的Java应用程序需要能够比较文件系统中的两个不同文件,并确定它们的二进制内容是否相同.
这是我目前的代码:
package utils;
import java.io.*;
class compare {
public static void main(String args[]) throws IOException {
FileInputStream file1 = new InputStream(args[0]);
FileInputStream file2 = new InputStream(args[1]);
try {
if(args.length != 2)
throw (new RuntimeException("Usage : java compare <filetoread> <filetoread>"));
while (true) {
int a = file1.read();
int b = file2.read();
if (a==-1) {
System.out.println("Both the files have same content");
}
else{
System.out.println("Contents are different");
}
}
}
catch (Exception e) {
System.out.println("Error: " + e);
}
}
}
Run Code Online (Sandbox Code Playgroud)
关于如何正确地进行比较功能的任何提示或建议将不胜感激.
我想从我的java applet中确定本地IP地址.问题是当同一台机器上有多个IP地址时,它们有LAN和互联网连接(掌上电脑,VMWare ......).
这是我的测试:
public static void main(String[] args) {
try {
String hostName = InetAddress.getLocalHost().getHostName();
System.out.println("HostName = " + hostName);
System.out.println("HostAddressLocal = " +
InetAddress.getLocalHost().getHostAddress());
InetAddress[] inetAddresses = InetAddress.getAllByName(hostName);
for (InetAddress inetAddress : inetAddresses) {
System.out.println("hostAddress = " + inetAddress.getHostAddress());
}
} catch (Exception e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
结果是:
HostName = xxxx
HostAddressLocal = xx.xx.xx.xx
hostAddress = 10.10.11.51
hostAddress = 192.168.23.1
hostAddress = 192.168.106.1
Run Code Online (Sandbox Code Playgroud)
其中xx.xx.xx.xx不是正确的地址.正确的是10.10.11.51.
编辑以回应jarnbjo:
你的水晶球说实话.你了解我的问题.客户端可以通过代理连接,因此我无法使用您的第一点.如果我在我的电脑上执行以下代码:
Socket s = new Socket("www.w3c.org", 80);
InetAddress ip = …Run Code Online (Sandbox Code Playgroud) 几乎普遍当人们在SO(或其他地方)上发布关于Perl和从文件中读取的问题时,如果任何涉及旧式开放的代码
open FH, ">file.txt" or die "Can't open for write, $!"; # OLD way, do not use!
Run Code Online (Sandbox Code Playgroud)
因不使用词法文件句柄而大喊大叫.众所周知,
open my $fh, ">", "file.txt" or die "Can't open for write, $!"; # new hotness
Run Code Online (Sandbox Code Playgroud)
是在现代Perl中打开文件句柄的正确方法.目录处理怎么样?在最近的一些SO问题中,人们提出了涉及的问题opendir,并发布了类似的代码
opendir DIR, "/directory" or die "Can't get the directory, wtf?! $!"; # ???
Run Code Online (Sandbox Code Playgroud)
该的perldoc页显示
opendir(my $dh, $some_dir) || die "can't opendir $some_dir: $!";
Run Code Online (Sandbox Code Playgroud)
作为例子.
我们是否应该建议人们为opendir使用词法目录句柄?
控制器:
DateTime startDate = DateTime.Now;
ViewData["now"] = startDate.ToString();
ViewData["interval"] = interval.ToString();
startDate.AddMonths(interval);
ViewData["later"] = startDate.ToString();
Run Code Online (Sandbox Code Playgroud)
视图:
Now: <%=ViewData["now"] %><br />
Later: <%=ViewData["later"] %><br />
Interval: <%=ViewData["interval"] %>
Run Code Online (Sandbox Code Playgroud)
这会产生:
Now: 10/2/2009 12:17:14 PM
Later: 10/2/2009 12:17:14 PM
Interval: 6
Run Code Online (Sandbox Code Playgroud) 如何从字符串创建动态对象?
这是我当前的代码,结果不正确:
var s1:String = '{x:200, y:400}';
var o1:Object = Object(s1);
trace(o1); // result = {x:200, y:400}
trace(o1.x) // result = ReferenceError: Error #1069: Property x not found on String and there is no default value.
trace(o1.y) // result = ReferenceError: Error #1069: Property x not found on String and there is no default value.
Run Code Online (Sandbox Code Playgroud)
我想以前的代码输出以下内容:
trace(o1); // result = [object Object]
trace(o1.x); // result = 200
trace(o1.y); // result = 400
Run Code Online (Sandbox Code Playgroud)
提前致谢!
我们都知道Jquery有很多好处.如果您在企业中使用过Jquery,那么您的"学习"体验是什么?
从向后兼容性,与现有的javascript冲突,CSS类结构,性能,jquery大小/缓存,其他插件等需要考虑什么来改善和利用Jquery的好处?
谢谢.
在.NET中是否有任何LGPL或商业友好许可的Jaro-Winkler距离实现?
.net ×3
java ×3
c# ×2
actionscript ×1
applet ×1
asp.net-mvc ×1
comparator ×1
datetime ×1
equals ×1
flash ×1
jaro-winkler ×1
javascript ×1
jquery ×1
networking ×1
perl ×1
rss ×1
sortedset ×1
xml ×1