2015-12-04 35 views
1
import java.util.Enumeration; 
import java.util.Hashtable; 

//@author fsociety 

public class HashFoo { 

public static void main(String[] args) { 
    HashFoo <String,String> student = new HashFoo <String,String>(); 

    student.put("1", "A");//Left side: Key , Right side: Value 
    student.put("2", "B");//Left side: Key , Right side: Value 
    student.put("3", "C");//Left side: Key , Right side: Value 
    student.put("4", "D");//Left side: Key , Right side: Value 
    student.put("5", "E");//Left side: Key , Right side: Value 
    student.put("6", "F");//Left side: Key , Right side: Value 
    student.put("7", "G");//Left side: Key , Right side: Value 
    student.put("8", "H");//Left side: Key , Right side: Value 

     System.out.println("Search this person 1 information: " + student.get("1"));//Get someone 
     System.out.println("Is the person I wrote type of KEY: " + student.containsKey("2")); 
     System.out.println("Is the person I wrote type of VALUE: " + student.containsValue("Z") + "\n"); 

    Enumeration enumerationValue = student.elements(); 
    Enumeration enumerationKeys = student.keys(); 
     System.out.println("Hash Table Values: "+"\n"); 

    while(enumerationValue.hasMoreElements() && enumerationKeys.hasMoreElements()){ 
     System.out.println(enumerationKeys.nextElement()+ " --> " + enumerationValue.nextElement() + "\n"); 
    } 

     System.out.println("Is student hashtable empty: " + student.isEmpty()); 
     System.out.println("Hashtable size: " + student.size()); 

} 

}如何在java中使用hashtable执行搜索方法?

我是新的,所以我会学习哈希随着时间的推移。现在,我想学习如何在主要中执行静态搜索,插入,删除方法。另外我怎样才能将键值存储在数组中?先谢谢你。 输出 搜索此人1点的信息:一个 是我写的主要类型的人:真正的 是我写的VALUE类型的人:假

哈希表值:

6 - >˚F

5 - >电子

4 - > d

3 - “ç

2 - >乙

1 - >甲

8 - >ħ

7 - “G

是学生散列表为空:假 哈希表的大小:8

我希望以这种形状搜索;

输出

1 - 搜索:..someone .. 2插入:..someone .. 3,删除:..someone ..

+0

目前尚不清楚。你有一个Map,并且你已经使用insert(put),search(contains),retrieve(get)。您也可以删除(删除)。您想做什么 ? –

+0

是的,它不清楚。我开始新的,所以我不知道我怎么能写模具。我不知道如何写关于搜索,删除,插入的方法,所以我想要所有这些,但它只是搜索方法就够了。 @guillaume girod-vitouchkina – fsociety

+0

.contains和.get ==搜索 – NickL

回答