python 对象转dict_如何将python dict对象转换为java等效对象?
總是有jython。
這里有一點來自this article,它提供了python/java的良好并排視圖The Jython analogues to Java's
collection classes are much more
tightly integrated into the core
language, allowing for more concise
descriptions and useful functionality.
For example, notice the difference
between the Java code:map = new HashMap();
map.put("one",new Integer(1));
map.put("two",new Integer(2));
map.put("three",new Integer(3));
System.out.println(map.get("one"));
list = new LinkedList();
list.add(new Integer(1));
list.add(new Integer(2));
list.add(new Integer(3));
and the Jython code:map = {"one":1,"two":2,"three":3}
print map ["one"]
list = [1, 2, 3]
編輯:僅僅使用put()替換值有什么問題?
map.put(key,new_value);
下面是一個小的示例程序:static public void main(String[] args){
HashMap map = new HashMap();
//name, age
map.put("billy", 21);
map.put("bobby", 19);
year(map);
for(String i: map.keySet()){
System.out.println(i+ " " + map.get(i).toString());
}
}
// a year has passed
static void year(HashMap m){
for(String k: m.keySet()){
m.put(k, m.get(k)+1);
}
}
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的python 对象转dict_如何将python dict对象转换为java等效对象?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: a b和c 15 java_1011.
- 下一篇: Python中关于文件路径的简单操作 [