【问题标题】:Hash based table returning null基于哈希的表返回 null
【发布时间】:2014-04-12 15:52:44
【问题描述】:

我有一个返回 null 的函数。

示例输入: String alice=table.get("Alice","Smith");

这是我的代码:

public void setTab() {
    table.put("Alice","Smith","Manager");
    ...
}

// get all persons with a surname of Smith
final Collection<String> smiths = table.column("Smith").values();

// get all persons with a firstName of Bob
final Collection<String> bobs = table.row("Bob").values();

// get a specific person
    final String alice=table.get("Alice", "Smith");

public void printSpecial() {
    System.out.println(alice);
    System.out.println(smiths);
    System.out.println(bobs);

}

public void prinTab()  {
    for (Cell<String, String,String> cell: table.cellSet()){
        System.out.println(cell.getRowKey()+" "+cell.getColumnKey()+" "+cell.getValue());
    }
}

【问题讨论】:

    标签: java guava


    【解决方案1】:

    对,它是空的,因为(除非你没有正确复制代码),行

    final String alice=table.get("Alice", "Smith");
    

    在类被实例化时调用。但是,您的 setTab() 函数大概是在那之后的某个时间才被调用。您可以通过在调用 setTab() 之前不设置 alice 来解决此问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多