java学了一点,然后仗着自己有点C语言的底子就上手学android是不可取的,卡在listview,adapter半天,json,xml都看不下去了,现在开始补课
输出为:
Map是一种<key,value>的构造方法,类似于xml,我在很多项目都看到过map,json,javabean的相互转换
下面是一个Map的例子,我重写了toString的方法
package leon.du.jsontest;
import java.util.*;
/**
* Created by leon on 14/7/13.
*/
public class JSONtest {
static public void main(String[] args) {
//Map 不能直接new,否则要自己重写,最好用直接的hashmap
//Integer 是 对象,而 int 是数据类型,Map 要求是对象
Map<Integer,Book> bookinf = new HashMap<Integer,Book>();
//key 是 键值,假设这里的key 就是书的出版编号
bookinf.put(00211,new Book("MCU",30));
bookinf.put(00212,new Book("DSP",25));
bookinf.put(00213,new Book("PCB",35));
//return Book.toString
System.out.println(bookinf.get(00211));
//boolean
System.out.println(bookinf.containsKey(00214));
System.out.println(bookinf.isEmpty());
System.out.println(bookinf.size());
System.out.println(bookinf.values());
}
}
class Book {
String name;
int value;
public Book (String name, int value)
{
this.name = name;
this.value = value;
}
@Override
public String toString() {
return "the value of "+name+" is "+ Integer.toString(value);
}
}
输出为:
the value of MCU is 30
false
false
3
[the value of MCU is 30, the value of PCB is 35, the value of DSP is 25]