HashMap<String, String> map =
new HashMap<String, String>();
map.put("Name", "June");
map.put("QQ", "2572073701");
HashMap<String, String> map =
new HashMap<String, String>() {
{
put("Name", "June");
put("QQ", "2572073701");
}
};
public class Test {
/*private static HashMap< String, String> map = new HashMap< String, String>() {
{
put("Name", "June");
put("QQ", "2572073701");
}
};*/
public Test() {
System.out.println("Constructor called:构造器被调用");
}
static {
System.out.println("Static block called:静态块被调用");
}
{
System.out.println("Instance initializer called:实例初始化块被调用");
}
public static void main(String[] args) {
new Test();
System.out.println("=======================");
new Test();
}
}
Static block called:静态块被调用 Instance initializer called:实例初始化被调用 Constructor called:构造器被调用 ======================= Instance initializer called:实例初始化被调用 Constructor called:构造器被调用
D:eclipse_indigoworkspace_homeCDHJobsbinpvuv>jad -p Test$1.class
// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov. // Jad home page: http://www.kpdus.com/jad.html // Decompiler options: packimports(3) // Source File Name: Test.java
package pvuv.zhaopin;
import java.util.HashMap;
// Referenced classes of package pvuv.zhaopin:
// Test
class Test$1 extends HashMap // 创建了一个 HashMap 的子类
{
Test$1()
{ // 第二个 {} 中的代码放到了构造方法中去了
put("Name", "June");
put("QQ", "2572073701");
}
}
D:eclipse_indigoworkspace_homeCDHJobsbinpvuv>
List<String> names = new ArrayList<String>() {
{
for (int i = 0; i < 10; i++) {
add("A" + i);
}
}
};
System.out.println(names.toString()); // [A0, A1, A2, A3, A4, A5, A6, A7, A8, A9]
List list = new ArrayList();
list.add("item");
String item = list.get(0);
Set< String> set = new HashSet< String>();
set.add("item");
Map< String, Integer> map = new HashMap< String, Integer>();
map.put("key", 1);
int value = map.get("key");
// 现在你还可以:
List< String> list = ["item"];
String item = list[0];
Set< String> set = {"item"};
Map< String, Integer> map = {"key" : 1};
int value = map["key"];
new HashMap(map);
public class Test {
public static void main(String[] args) {
long st = System.currentTimeMillis();
/*
for (int i = 0; i < 10000000; i++) {
HashMap< String, String> map = new HashMap< String, String>() {
{
put("Name", "June");
put("QQ", "2572073701");
}
};
}
System.out.println(System.currentTimeMillis() - st); // 1217
*/
for (int i = 0; i < 10000000; i++) {
HashMap< String, String> map = new HashMap< String, String>();
map.put("Name", "June");
map.put("QQ", "2572073701");
}
System.out.println(System.currentTimeMillis() - st); // 1064
}
}
public class Test {
int e = 6;
Test() {
int c = 1;
this.f = 5;
int e = 66;
}
int f = 55;
int c = 11;
int b = 1;
{
a = 3;
b = 22;
}
int a = 33;
static {
d = 4;
}
static int d = 44;
int g = 7;
int h = 8;
public int test(){
g = 77;
int h = 88;
System.out.println("h - 成员变量:" + this.h);
System.out.println("h - 局部变量: " + h);
return g;
}
public static void main(String[] args) {
System.out.println("a: " + new Test().a);
System.out.println("b: " + new Test().b);
System.out.println("c: " + new Test().c);
System.out.println("d: " + new Test().d);
System.out.println("f: " + new Test().f);
System.out.println("e: " + new Test().e);
System.out.println("g: " + new Test().test());
}
}
// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3)
// Source File Name: Test.java
import java.io.PrintStream;
public class Test
{
Test()
{
this.e = 6;
f = 55;
this.c = 11;
b = 1;
a = 3;
b = 22;
a = 33;
g = 7;
h = 8;
int c = 1;
f = 5;
int e = 66;
}
public int test()
{
g = 77;
int h = 88;
System.out.println((new StringBuilder("h - u6210u5458u53D8u91CFuFF1A")).append(this.h).toString());
System.out.println((new StringBuilder("h - u5C40u90E8u53D8u91CF: ")).append(h).toString());
return g;
}
public static void main(String args[])
{
System.out.println((new StringBuilder("a: ")).append((new Test()).a).toString());
System.out.println((new StringBuilder("b: ")).append((new Test()).b).toString());
System.out.println((new StringBuilder("c: ")).append((new Test()).c).toString());
new Test();
System.out.println((new StringBuilder("d: ")).append(d).toString());
System.out.println((new StringBuilder("f: ")).append((new Test()).f).toString());
System.out.println((new StringBuilder("e: ")).append((new Test()).e).toString());
System.out.println((new StringBuilder("g: ")).append((new Test()).test()).toString());
}
int e;
int f;
int c;
int b;
int a;
static int d = 4;
int g;
int h;
static
{
d = 44;
}
}
6.3 output:
a: 33
b: 22
c: 11
d: 44
f: 5
e: 6
h - 成员变量:8
h - 局部变量: 88
g: 77
Map map = new HashMap();
Iterator iter = map.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry) iter.next(); Object key = entry.getKey();
Object val = entry.getValue();
}
Map map = new HashMap();
Iterator iter = map.keySet().iterator();
while (iter.hasNext()) {
Object key = iter.next();
Object val = map.get(key);
}
public class HashMapTest {
public static void main(String[] args) ...{
HashMap hashmap = new HashMap();
for (int i = 0; i < 1000; i ) ...{
hashmap.put("" i, "thanks");
}
long bs = Calendar.getInstance().getTimeInMillis();
Iterator iterator = hashmap.keySet().iterator();
while (iterator.hasNext()) ...{
System.out.print(hashmap.get(iterator.next()));
}
System.out.println();
System.out.println(Calendar.getInstance().getTimeInMillis() - bs);
listHashMap();
}
public static void listHashMap() ...{
java.util.HashMap hashmap = new java.util.HashMap();
for (int i = 0; i < 1000; i ) ...{
hashmap.put("" i, "thanks");
}
long bs = Calendar.getInstance().getTimeInMillis();
java.util.Iterator it = hashmap.entrySet().iterator();
while (it.hasNext()) ...{
java.util.Map.Entry entry = (java.util.Map.Entry) it.next();
// entry.getKey() 返回与此项对应的键
// entry.getValue() 返回与此项对应的值
System.out.print(entry.getValue());
}
System.out.println();
System.out.println(Calendar.getInstance().getTimeInMillis() - bs);
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有