问题如下:
List<InProperties> list = new ArrayList<InProperties>();
list.add(new InProperties("2222", "name", "you"));
list.add(new InProperties("2222", "phone", "139"));
list.add(new InProperties("2222", "email", "[email protected]")); List alllist = new ArrayList();
        list2.add(list);
        list2.add("user2"); List<InProperties> list2 = new ArrayList<InProperties>();
list2.add(new InProperties("3333", "name", "she"));
list2.add(new InProperties("3333", "phone", "138"));
list2.add(new InProperties("2222", "email", "[email protected]"));
        alllist.add(list);
        alllist.add("user3");..............alllist 这个List是存放用户的属性,和改用户的ID号,
list,list2,list3.....这些是用户的属性
以上这个结构可以随便怎么设置, 比如你想用HASHMAP, 或其它的数据结构
只要表达个意思就可了, 现有字段name, phone, industry, email, interest. 我想用一个HASHM或ARRAYLIST存储以下数据
HashMap中存放的数据要按name, phone, industry, email, interest. 这个顺序, 如果那个LIST中没这个值, 就用&nbsp;表示
比如list中没有industry这个值, 就用&nbsp;表示Map map = new HashMap();
map.put("<td>you</td><td>139</td><td>&nbsp;</td><td>[email protected]</td><td>&nbsp;</td>");
map.put("<td>she</td><td>138</td><td>&nbsp;</td><td>[email protected]</td><td>&nbsp;</td>");
...........
有没有高效的算法能处理这个问题, 尤其是时间的长短?
InProperties代码如下class InProperties {
InProperties(String ID, String properties, String value) {
this.ID = ID;
this.properties = properties;
this.value = value; } private String ID; public String getID() {
return ID;
} public void setID(String id) {
ID = id;
} public String getProperties() {
return properties;
} public void setProperties(String properties) {
this.properties = properties;
} public String getValue() {
return value;
} public void setValue(String value) {
this.value = value;
} private String properties;
private String value;
}

解决方案 »

  1.   

    便于理解, 重新修改一下
    问题如下:
                List all = new ArrayList();                //用户2的所有属性
    List<InProperties> list2 = new ArrayList<InProperties>();
    list2.add(new InProperties("2222", "name", "you"));
    list2.add(new InProperties("2222", "phone", "139"));
    list2.add(new InProperties("2222", "email", "[email protected]"));        // user2 存放用户2以及其属性
    List user2 = new ArrayList();
            user2.add(list2);
            user2.add("user2");       // 所用用户添加到ALL中
             all.add(user2);       //用户3的所有属性
    List<InProperties> list3 = new ArrayList<InProperties>();
    list3.add(new InProperties("3333", "name", "she"));
    list3.add(new InProperties("3333", "phone", "138"));
    list3.add(new InProperties("2222", "email", "[email protected]"));        // user3 存放用户3以及其属性
    List user3 = new ArrayList();
            user3.add(list3);
            user3.add("user3");         // 所用用户添加到ALL中
            all.add(user3);
    ..............all 这个List是存放每个用户的属性,和改用户的ID号,
    list2,list3.....这些是用户的属性
    以上这个结构可以随便怎么设置, 比如你想用HASHMAP, 或其它的数据结构
    只要表达个意思就可了, 现有字段name, phone, industry, email, interest. 我想用一个HASHM或ARRAYLIST存储以下数据
    HashMap中存放的数据要按name, phone, industry, email, interest. 这个顺序, 如果那个LIST中没这个值(用户没有这个属性时), 就用&nbsp;表示
    比如list2中没有industry这个值(用户2没有行业这个属性), 就用&nbsp;表示Map map = new HashMap();
    map.put("<td>you</td><td>139</td><td>&nbsp;</td><td>[email protected]</td><td>&nbsp;</td>");
    map.put("<td>she</td><td>138</td><td>&nbsp;</td><td>[email protected]</td><td>&nbsp;</td>");
    ...........
    有没有高效的算法能处理这个问题, 尤其是时间的长短?
    InProperties代码如下class InProperties {
    InProperties(String ID, String properties, String value) {
    this.ID = ID;
    this.properties = properties;
    this.value = value; } private String ID; public String getID() {
    return ID;
    } public void setID(String id) {
    ID = id;
    } public String getProperties() {
    return properties;
    } public void setProperties(String properties) {
    this.properties = properties;
    } public String getValue() {
    return value;
    } public void setValue(String value) {
    this.value = value;
    } private String properties;
    private String value;
    }
      

  2.   

    用户有一些name, email, interest这些属性, 以及一个用户ID ,如“2222”,这些数据是从数据库中拿到的现在有一个问题是我想把用户的属性按name, phone, industry, email, interest. 这个顺序显示用户, 如查这个用户没有值,当然就显示为空, 但改须是这个顺序
      

  3.   

    我感觉这种在设计上就有问题。为什么不使用一个
    User(id, name, phone, industry, email, interest) 的对象啊?
      

  4.   

    Map<String "user2",List<InProperties> list2>
    InProperties 的属性
    如果属性的最大个数确定,最好用Object[] = new Object[length]
    public static final int ID=0;
    public static final int NAME=1;
    public static final int PHONE=2; 
    if(Object[arg0] != null) return Object[arg0].toString();
    else "&nbsp;";
    如果不想用Object[],也可以用Map<Integer or String,Object>(除非有特殊作用,否则的话,用Map效率比不上Object[])
      

  5.   

    对象模型就没建好,这样存储效率太低,处理起来相当麻烦。如果每个用户属性个数可变,可以在 User 类里再维护一个属性 List 或 Map (Map 更合适,Key Value 分别对应属性名和属性值),然后再将 User 对象放到 List 中,这样以后排序和操作都方便。