How to iterate over a TreeMap?

Possible Duplicate: How do I iterate over each Entry in a Map? I want to iterate over a TreeMap , and for all keys which have a particular value, I want them to be added to a new TreeMap . How can I do this? Assuming type TreeMap<String,Integer> : for(Map.Entry<String,Integer> entry : treeMap.entrySet()) { String key = entry.getKey(); Integer value = entry.getValue(); S

如何遍历TreeMap?

可能重复: 如何迭代Map中的每个条目? 我想迭代一个TreeMap ,对于所有具有特定值的键,我希望它们被添加到一个新的TreeMap 。 我怎样才能做到这一点? 假设类型为TreeMap <String,Integer>: for(Map.Entry<String,Integer> entry : treeMap.entrySet()) { String key = entry.getKey(); Integer value = entry.getValue(); System.out.println(key + " => " + value); } (键和值类型可以是

Send one SMS to Multiple phone numbers

i have an arraylist of phone numbers. when i send a message it only sends to the last number on the list. here is my code public void onActivityResult(int requestCode,int resultCode,Intent data){ super.onActivityResult(requestCode, resultCode, data); if(requestCode == CONTACT_PICK_REQUEST && resultCode == RESULT_OK){ ArrayList<Contact> selectedContacts = data.getPa

发送一条短信至多个电话号码

我有一个电话号码arraylist。 当我发送一条消息时,它只发送到列表中的最后一个数字。 这是我的代码 public void onActivityResult(int requestCode,int resultCode,Intent data){super.onActivityResult(requestCode,resultCode,data); if(requestCode == CONTACT_PICK_REQUEST && resultCode == RESULT_OK){ ArrayList<Contact> selectedContacts = data.getParcelableArrayListExtra(

getting file creator/owner attributes in Java

I am trying to read in a list of files and find the user who created the file. With a *nix system, you can do something like Map<String, Object> attrs = Files.readAttributes(Paths.get(filename), "posix:*"); However, when attempting it on a Windows system, I get an error because Windows is not able to access the POSIX properties. You can get the "regular" (non POSIX) properties

在Java中获取文件创建者/所有者属性

我正在尝试读取文件列表并找到创建该文件的用户。 用* nix系统,你可以做类似的事情 Map<String, Object> attrs = Files.readAttributes(Paths.get(filename), "posix:*"); 但是,在Windows系统上尝试它时,出现错误,因为Windows无法访问POSIX属性。 您可以通过执行以下操作来获得“常规”(非POSIX)属性: attrs = Files.readAttributes(Paths.get(filename), "*"); 但该文件的创建者不包含在该列表中。 有什么方

No operations allowed after connection closed

I'm getting this error from a Java application: com.mchange.v2.c3p0.impl.NewPooledConnection - [c3p0] Another error has occurred [ com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed. ] which will not be reported to listeners! The Java code: try { sessionFactory.beginTransaction(); //... sessionFactory.comm

关闭连接后不允许任何操作

我从Java应用程序中收到这个错误: com.mchange.v2.c3p0.impl.NewPooledConnection - [c3p0] Another error has occurred [ com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed. ] which will not be reported to listeners! Java代码: try { sessionFactory.beginTransaction(); //... sessionFactory.commitTransaction(); } catc

Is instantiating a member of class Test within class Test a recursion?

Is this recursion? public class Test { Test test = new Test(); public static void main(String[] args) { new Test(); } } What about version with instance initalizer? public class Test { { Test test = new Test(); } public static void main(String[] args) { new Test(); } } I'm asking, because I updated my old answer, which was showing how to make Stac

在类中实例化类Test的成员测试递归?

这是递归吗? public class Test { Test test = new Test(); public static void main(String[] args) { new Test(); } } 实例initalizer的版本怎么样? public class Test { { Test test = new Test(); } public static void main(String[] args) { new Test(); } } 我在问,因为我更新了我的旧回答,这是显示如何使StackOverflowError没有递归,但现在我不是100%确定上面的代

Applet (does not declare a static final serialVersionUID field of type long)

I just began learning Java programming. I made this one program given in the first chapter on Applets (The applet class) and it gave me this error. I tried to find a solution but couldn't. According to the book this program should display a window but I get this error when I extend the Applet class : "Multiple markers at this line - The serializable class AppletSkel does not declar

Applet(不声明long类型的静态最终serialVersionUID字段)

我刚开始学习Java编程。 我在Applets的第一章中给出了这个程序(Applet类),它给了我这个错误。 我试图找到一个解决方案,但不能。 根据这本书,这个程序应该显示一个窗口,但是当我扩展Applet类时,出现这个错误: “此行的多个标记 - 可序列化的类AppletSkel不声明long类型的静态最终serialVersionUID字段 - 公共类型AppletSkel必须在其自己的文件中定义” 这是我的代码 //An Applet Skeleton import java.awt.*; impo

Why is String class declared final in Java?

From when I learned that the class java.lang.String is declared as final in Java, I was wondering why is that? I didn't find any answer back then, but this post: How to create a replica of String class in Java? reminded me of my query. Sure, String provides all the functionality I ever needed, and never thought of any operation that would require an extension of class String, but still yo

为什么String类在Java中声明为final?

从我得知java.lang.String类在Java中被声明为final时,我想知道为什么会这样? 我当时没有找到答案,但是这篇文章:如何在Java中创建String类的副本? 提醒了我的查询。 当然,String提供了我所需要的所有功能,并且从来没有想过任何需要扩展类String的操作,但是你永远不会知道某人可能需要什么! 那么,有没有人知道设计师决定什么时候决定做最终决定? 将字符串实现为不可变对象是非常有用的。 你应该阅读关于不变性

Same Serial version id for all the classes?

Java specification stats that The serialization runtime associates with each serializable class a version number, called a serialVersionUID, which is used during deserialization to verify that the sender and receiver of a serialized object have loaded classes for that object that are compatible with respect to serialization. If the receiver has loaded a class for the object that has a differen

所有类都有相同的串行版本ID?

Java规范统计了这一点 序列化运行时与每个可序列化类关联一个称为serialVersionUID的版本号,在反序列化过程中使用该版本号来验证序列化对象的发送者和接收者是否已加载该对象的与序列化相容的类。 如果接收者已经为与对应的发送者类具有不同serialVersionUID的对象加载了类,则反序列化将导致InvalidClassException。 enter code here 但是,如果我将所有类的相同序列版本ID分配如下 static final long serialVersionUID =

why user defined serialVersionUID is not used while desialization?

public class Employee2 implements java.io.Serializable { private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } } i first serialized the Employee2 object.Then added one more field ie age under Employee2. Now deserialize the Employee2 and get the below error java.io.InvalidClassException: Test.Employee2; local

为什么用户定义的serialVersionUID在去电时不使用?

public class Employee2 implements java.io.Serializable { private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } } 我首先序列化Employee2对象。然后在Employee2下添加一个字段,即年龄。 现在反序列化Employee2并获取下面的错误 java.io.InvalidClassException:Test.Employee2; 本地类不兼容:stream classdesc serialVersion

serialversionuid is static and final but then why is it serializable

As we know that static fields are not serializable, but the serialversionUID in our class is final and static, How is it serialized even if it is static and final During the serialization process, one of the things that gets written is the class descriptor. This class descriptor contains the name and the serialVersionUID of the class. The method can be found in the class java.io.ObjectStre

serialversionuid是静态的和最终的,但为什么它是可序列化的

由于我们知道静态字段不可序列化, 但是我们类中的serialversionUID是final和static的,即使它是静态的也是最终的,它是如何序列化的 在序列化过程中,写入的内容之一是类描述符。 这个类描述符包含类的名称和serialVersionUID。 该方法可以在java.io.ObjectStreamClass类中找到(http://docs.oracle.com/javase/7/docs/api/java/io/ObjectStreamClass.html) /** * Writes non-proxy class descriptor information to g