看java doc,上面写的很详细.
解决方案 »
- spring事务??
- 求助:应届毕业生选择java ee和webapp、webservices哪个好
- struts求助:执行action后如何返回原来的页面(在线等)
- 发布webservice遇到Selection must be WSDL怎样解决
- J2EE项目里JXL生成excel并导出的问题
- 为什么str.replaceAll("location in ('HK')","location not in ('HK','TP')");不能替换
- 中文字符输出问题
- EJB的中文问题
- 请问如何将写好的struts打包发布到weblogic上
- poi读取2003正常,为什么读取不到2007的
- Ibatis的排序问题
- 关于在struts中的Hibernate的数据连接池的问题
Map 也是一个接口,但它实现了Collection这个父接口,它的实现类有:HashMap,Hashtable,TreeMap...等,主要是保存键值对的集合
List 它还是个接口,还是实现了Collection接口,它的实现类有:
ArrayList,Vector等,它对于加入到其中的对象是有序排列的,可以通过
索引来获得里面的值,如:XXX.get(0);
另外(你应该已经知道了),这些接口是不能直接用的,我们主要是用它们的
实现类,上面我列出的这些实现类都是很常用的。
其实,他们还包括一个重要的伙伴Set借口,它的常用实现类有:HashSet,TreeSet...
记住:它们的特点是,不能加入相同的对象,用书面一点的话说就是不包含重复对象,
如果你向HashSet里加入N个相同对象,它的里面实际上只存在一个,其他的被它干掉了欢迎大家来我的BLOG做客,开张才3个月:
http://www.blogjava.net/lbx19822004
--- 冰川
基本上不用去理它。
分别封装了平时所见的数据结构
找本讲java数据结构的数看看
map的例程
/**
@version 1.10 2004-08-02
@author Cay Horstmann
*/import java.util.*;/**
This program demonstrates the use of a map with key type
String and value type Employee.
*/
public class MapTest
{
public static void main(String[] args)
{
Map<String, Employee> staff = new HashMap<String, Employee>();
staff.put("144-25-5464", new Employee("Amy Lee"));
staff.put("567-24-2546", new Employee("Harry Hacker"));
staff.put("157-62-7935", new Employee("Gary Cooper"));
staff.put("456-62-5527", new Employee("Francesca Cruz")); // print all entries System.out.println(staff); // remove an entry staff.remove("567-24-2546"); // replace an entry staff.put("456-62-5527", new Employee("Francesca Miller")); // look up a value System.out.println(staff.get("157-62-7935")); // iterate through all entries for (Map.Entry<String, Employee> entry : staff.entrySet())
{
String key = entry.getKey();
Employee value = entry.getValue();
System.out.println("key=" + key + ", value=" + value);
}
}
}/**
A minimalist employee class for testing purposes.
*/
class Employee
{
/**
Constructs an employee with $0 salary.
@param n the employee name
*/
public Employee(String n)
{
name = n;
salary = 0;
} public String toString()
{
return "[name=" + name + ", salary=" + salary + "]";
} private String name;
private double salary;
}
/**
@version 1.10 2004-08-02
@author Cay Horstmann
*/import java.util.*;/**
This program demonstrates operations on linked lists.
*/
public class LinkedListTest
{
public static void main(String[] args)
{
List<String> a = new LinkedList<String>();
a.add("Amy");
a.add("Carl");
a.add("Erica"); List<String> b = new LinkedList<String>();
b.add("Bob");
b.add("Doug");
b.add("Frances");
b.add("Gloria"); // merge the words from b into a ListIterator<String> aIter = a.listIterator();
Iterator<String> bIter = b.iterator(); while (bIter.hasNext())
{
if (aIter.hasNext()) aIter.next();
aIter.add(bIter.next());
} System.out.println(a); // remove every second word from b bIter = b.iterator();
while (bIter.hasNext())
{
bIter.next(); // skip one element
if (bIter.hasNext())
{
bIter.next(); // skip next element
bIter.remove(); // remove that element
}
} System.out.println(b); // bulk operation: remove all words in b from a a.removeAll(b); System.out.println(a);
}
}
/**
@version 1.10 2003-08-02
@author Cay Horstmann
*/import java.util.*;/**
This program uses a set to print all unique words in
System.in.
*/
public class SetTest
{
public static void main(String[] args)
{
Set<String> words = new HashSet<String>(); // HashSet implements Set
long totalTime = 0; Scanner in = new Scanner(System.in);
while (in.hasNext())
{
String word = in.next();
long callTime = System.currentTimeMillis();
words.add(word);
callTime = System.currentTimeMillis() - callTime;
totalTime += callTime;
} Iterator<String> iter = words.iterator();
for (int i = 1; i <= 20; i++)
System.out.println(iter.next());
System.out.println(". . .");
System.out.println(words.size() + " distinct words. " + totalTime + " milliseconds.");
}
}
找那个中文的chm版本就可以了..其实,用不着太清楚,多做项目就可以了..我比较常用的是:Map (HashMap) , List (ArrayList), Set不太会用.. Collection更不会用..
快来看看,腾迅为庆祝腾讯QQ七周年,现在开放六位 QQ 号码免费申请,数量有限,送完即止
~~~~~~~
好像不是哦,,实现Collection的是set和list才对吧?
Map不是实现了Collection哦?
===Set是HashSet TreeSet的接口;
===List是ArrayList Vector LinkedList的接口Map是与Collection并列的接口,
===是HashMap、TreeMap的接口。另外,所有的这一切都属于Collection Framework