想实现这种效果:
key               value
广东         广州,深圳
put( "广东" , "佛山" );
变成
key               value
广东         广州,深圳 , 佛山这里的逗号只是为了分开这几个对象
实际不仅仅存String,存Object这个肯定用Map,但我看了Hashtable,HashMap都不行,
上数据结构课的时候有这中国,Java里居然没有?
顺便问句,C#里有没有可以实现类似数据结构的?

解决方案 »

  1.   

    上数据结构课的时候有这中国,Java里居然没有?
    ---------------------------------------
    这句打的快,有笔误
      

  2.   

    dreamover(梦醒了) ( ) 信誉:100  2006-08-15 15:24:00  得分: 0  
     
     
       切~~~
      
     
    -----------------------
    你有资格 切 吗,能回答问题,你再切,
      

  3.   

    C++
    std::map<string, vector<string> >
    Java
    HashMap<String, Vector<String>>
    C#
    Hashtable<string, ArrayList<string>>
      

  4.   

    dreamover(梦醒了) ( ) 信誉:100  2006-08-15 15:33:00  得分: 0  
     
     
       什么都要现成的?那要你来干什么再说你那什么破数据结构
      
     
    -------------------------------------
    人家C族里都这么体贴的有这种东西,你还说什么破数据结构
      

  5.   

    晕死,怎么没有?
    HashMap<String,List<String>> xxMap=new HashMap<String,List<String>>();
    List<String > values=new ArrayList<String>();
    values.add("GZ");
    values.add("SZ");            //XZsit
    xxMap.put("GD",values);
      

  6.   

    treeroot(旗鲁特) ( ) 信誉:106  2006-08-15 15:38:00  得分: 0  
     
     
       晕死,怎么没有?
    HashMap<String,List<String>> xxMap=new HashMap<String,List<String>>();
    List<String > values=new ArrayList<String>();
    values.add("GZ");
    values.add("SZ");            //XZsit
    xxMap.put("GD",values);
    ------------------------------
    范型只是用起来精确,不用转型,不是我要的那种数据结构啊,比如是返回了一个ArrayList,但这个ArrayList还得由你来维护啊,我要的是由该数据结构自己维护。
      

  7.   

    我记得上数据结构课的时候有这种,怎么Java就没有实现的util类呢?
      

  8.   

    哥们,这种已经是最简便的方式了,你只要再简单的封装一下就可以了。class MyMap {private HashMap<String,List<String>> xxMap=new HashMap<String,List<String>>();public void put(String , String) {
        里面处理List的建立和取出,和字符串的插入就可以了。
    }};
      

  9.   

    没办法啊,现在就正在自己写
    Sun为什么不加上这个呢,这个应该会用到的啊?既然数据结构课里有,那么Sun就不应该漠视这个,一定是有什么原因
      

  10.   

    用到什么地名可以,如果别的带“,”的字符串呢put("key1","aa");
    pub("key2","bb,cc");数据变成
    key1 :  aa,bb,cc这时候是把它看成aa、bb、cc三个元素,还是aa、bb,cc两个元素?还是那句话,什么破数据结构,不知道你看的什么破书
      

  11.   

    healer_kx(甘草(现在正是我事业的上升期~)) 
    ------------------------
    少不了你的~
      

  12.   

    dreamover(梦醒了) ( ) 信誉:100  2006-08-15 16:04:00  得分: 0  
     
     
       用到什么地名可以,如果别的带“,”的字符串呢put("key1","aa");
    pub("key2","bb,cc");数据变成
    key1 :  aa,bb,cc这时候是把它看成aa、bb、cc三个元素,还是aa、bb,cc两个元素?还是那句话,什么破数据结构,不知道你看的什么破书
      
     
    ----------------------------------------
    唉,真实败给你了,我都说了
    这里的逗号只是为了分开这几个对象
    实际不仅仅存String,存Object重话不说你了,你好自为之吧~
      

  13.   

    .NET Framework里面还真有一个类似的,但不是干这个用的。System.Collections.Specialized.NameValueCollection引用上面的这句话:一个好得类库是让你什么都能实现而不是什么都帮你实现。
      

  14.   

    这个可能是你想要的吧?
    org.apache.commons.collections 
    Interface MultiMap
    All Superinterfaces: 
    java.util.Map 
    All Known Implementing Classes: 
    MultiHashMap --------------------------------------------------------------------------------public interface MultiMap
    extends java.util.Map
    Defines a map that holds a collection of values against each key. A MultiMap is a Map with slightly different semantics. Putting a value into the map will add the value to a Collection at that key. Getting a value will return a Collection, holding all the values put to that key. For example:  MultiMap mhm = new MultiHashMap();
     mhm.put(key, "A");
     mhm.put(key, "B");
     mhm.put(key, "C");
     Collection coll = (Collection) mhm.get(key);coll will be a collection containing "A", "B", "C". NOTE: Additional methods were added to this interface in Commons Collections 3.1. These were added solely for documentation purposes and do not change the interface as they were defined in the superinterface Map anyway. Since: 
    Commons Collections 2.0 
    Version: 
    $Revision: 1.12 $ $Date: 2004/03/14 15:33:57 $ 
    Author: 
    Christopher Berry, James Strachan, Stephen Colebourne --------------------------------------------------------------------------------Method Summary 
     boolean containsValue(java.lang.Object value) 
              Checks whether the map contains the value specified. 
     java.lang.Object get(java.lang.Object key) 
              Gets the collection of values associated with the specified key. 
     java.lang.Object put(java.lang.Object key, java.lang.Object value) 
              Adds the value to the collection associated with the specified key. 
     java.lang.Object remove(java.lang.Object key) 
              Removes all values associated with the specified key. 
     java.lang.Object remove(java.lang.Object key, java.lang.Object item) 
              Removes a specific value from map. 
     int size() 
              Gets the number of keys in this map. 
     java.util.Collection values() 
              Gets a collection containing all the values in the map. 
      Methods inherited from interface java.util.Map 
    clear, containsKey, entrySet, equals, hashCode, isEmpty, keySet, putAll 
      Method Detail 
    remove
    public java.lang.Object remove(java.lang.Object key,
                                   java.lang.Object item)Removes a specific value from map. 
    The item is removed from the collection mapped to the specified key. Other values attached to that key are unaffected. If the last value for a key is removed, implementations typically return null from a subsequant get(Object), however they may choose to return an empty collection. 
    Parameters:
    key - the key to remove from
    item - the item to remove 
    Returns:
    the value removed (which was passed in), null if nothing removed 
    Throws: 
    java.lang.UnsupportedOperationException - if the map is unmodifiable 
    java.lang.ClassCastException - if the key or value is of an invalid type 
    java.lang.NullPointerException - if the key or value is null and null is invalid--------------------------------------------------------------------------------size
    public int size()Gets the number of keys in this map. 
    Implementations typically return only the count of keys in the map This cannot be mandated due to backwards compatability of this interface. 
    Specified by:
    size in interface java.util.Map
    Returns:
    the number of key-collection mappings in this map--------------------------------------------------------------------------------get
    public java.lang.Object get(java.lang.Object key)Gets the collection of values associated with the specified key. 
    The returned value will implement Collection. Implementations are free to declare that they return Collection subclasses such as List or Set. Implementations typically return null if no values have been mapped to the key, however the implementation may choose to return an empty collection. Implementations may choose to return a clone of the internal collection. 
    Specified by:
    get in interface java.util.Map
    Parameters:
    key - the key to retrieve 
    Returns:
    the Collection of values, implementations should return null for no mapping, but may return an empty collection 
    Throws: 
    java.lang.ClassCastException - if the key is of an invalid type 
    java.lang.NullPointerException - if the key is null and null keys are invalid--------------------------------------------------------------------------------containsValue
    public boolean containsValue(java.lang.Object value)Checks whether the map contains the value specified. 
    Implementations typically check all collections against all keys for the value. This cannot be mandated due to backwards compatability of this interface. 
    Specified by:
    containsValue in interface java.util.Map
    Parameters:
    value - the value to search for 
    Returns:
    true if the map contains the value 
    Throws: 
    java.lang.ClassCastException - if the value is of an invalid type 
    java.lang.NullPointerException - if the value is null and null value are invalid--------------------------------------------------------------------------------put
    public java.lang.Object put(java.lang.Object key,
                                java.lang.Object value)Adds the value to the collection associated with the specified key. 
    Unlike a normal Map the previous value is not replaced. Instead the new value is added to the collection stored against the key. The collection may be a List, Set or other collection dependent on implementation. 
    Specified by:
    put in interface java.util.Map
    Parameters:
    key - the key to store against
    value - the value to add to the collection at the key 
    Returns:
    typically the value added if the map changed and null if the map did not change 
    Throws: 
    java.lang.UnsupportedOperationException - if the map is unmodifiable 
    java.lang.ClassCastException - if the key or value is of an invalid type 
    java.lang.NullPointerException - if the key or value is null and null is invalid 
    java.lang.IllegalArgumentException - if the key or value is invalid--------------------------------------------------------------------------------remove
    public java.lang.Object remove(java.lang.Object key)Removes all values associated with the specified key. 
    Implementations typically return null from a subsequant get(Object), however they may choose to return an empty collection. 
    Specified by:
    remove in interface java.util.Map
    Parameters:
    key - the key to remove values from 
    Returns:
    the Collection of values removed, implementations should return null for no mapping found, but may return an empty collection 
    Throws: 
    java.lang.UnsupportedOperationException - if the map is unmodifiable 
    java.lang.ClassCastException - if the key is of an invalid type 
    java.lang.NullPointerException - if the key is null and null keys are invalid--------------------------------------------------------------------------------values
    public java.util.Collection values()Gets a collection containing all the values in the map. 
    Inplementations typically return a collection containing the combination of values from all keys. This cannot be mandated due to backwards compatability of this interface. 
    Specified by:
    values in interface java.util.Map
    Returns:
    a collection view of the values contained in this map
      

  15.   

    sevencat(七猫) ( 
    =----------------------
    just it!
      

  16.   

    C#Dictionary<String,List<String>> haha=new Dictionary<string,List<string>>();
    List<String> gaga = new List<string>();
    gaga.Add("广州");
    gaga.Add("深圳");
    haha.Add("广东", gaga);
    haha["广东"].Add("佛山");