코딩하던 중 여러 hashTable을 사용하게 되었다. 한 3개??
재사용하기 위해서 메소드 찾아보던 중 clear() 라는 걸 발견
The java.util.Hashtable.clear() method in Java is used to clear and remove all of the keys from a specified Hashtable.
Syntax:
Hash_table.clear()
Parameters: The method does not accept any parameters.
Return Value: The method does not return any value.
// Java code to illustrate the clear() method
import java.util.*;
public class Hash_Table_Demo {
public static void main(String[] args)
{
// Creating an empty Hashtable
Hashtable<Integer, String> hash_table = new Hashtable<Integer, String>();
// Inserting Values into table
hash_table.put(10, "Geeks");
hash_table.put(15, "4");
hash_table.put(20, "Geeks");
hash_table.put(25, "Welcomes");
hash_table.put(30, "You");
// Displaying the Hashtable
System.out.println("The Hashtable is: " + hash_table);
// Clearing the hash table using clear()
hash_table.clear();
// Displaying the final Hashtable
System.out.println("Finally the table looks like this: " + hash_table);
}
}
OutPut->
The Hashtable is: {10=Geeks, 20=Geeks, 30=You, 15=4, 25=Welcomes}
Finally the table looks like this: {}
+ ************************************************************
사용했던 hashTable을 다시 사용하려면 ...
clear() 가 아니라
hash_table = new Hashtable<String, String>();
hash_table2 = new Hashtable<String, String>();
hash_table = resultString;
이런식으로 사용한다. 중요!
참고 https://www.geeksforgeeks.org/hashtable-clear-method-in-java/
Hashtable clear() Method in Java - GeeksforGeeks
The java.util.Hashtable.clear() method in Java is used to clear and remove all of the keys from a specified Hashtable. Syntax: Hash_table.clear() Parameters: The method does… Read More »
www.geeksforgeeks.org
'Programming > JAVA' 카테고리의 다른 글
[Java] substring , indexOf , charAt 을 이용한 문자열 (0) | 2019.08.24 |
---|---|
hashTable 이용해서 단어들 조합하기 (1) | 2019.08.23 |
HashTable 예제 (0) | 2019.08.21 |