hashsetuse.java

来自「JAVA编程思想源代码 值得一下 很难找的」· Java 代码 · 共 55 行

JAVA
55
字号
package chapter9;

import java.util.*;

public class HashSetUse {

	public static void main(String[] args) {

		HashSet s = new HashSet();

		Character chars = new Character('C');
		System.out.println("chars hasCode is:" + chars.hashCode());
		s.add(chars);

		String s1 = new String("hello");
		System.out.println("s1 hasCode is:" + s1.hashCode());
		s.add(s1);

		String s2 = new String("World");
		System.out.println("s2 hasCode is:" + s2.hashCode());
		s.add(s2);

		Integer itn = new Integer(23);
		System.out.println("itn hasCode is:" + itn.hashCode());
		s.add(itn);

		Double dou = new Double(33.33);
		System.out.println("dou hasCode is:" + dou.hashCode());
		s.add(dou);

		s.add(null);

		Iterator iter = s.iterator();
		System.out.println("begin: ");
		while (iter.hasNext()) {
			System.out.println(iter.next() + ", ");

		}
		System.out.println("end. ");
		System.out.println("the word 'world in s is :'" + s.contains("World"));
		System.out.println(s.hashCode());
		s.remove('C');

		iter = s.iterator();
		System.out.println("begin: ");
		while (iter.hasNext()) {
			System.out.println(iter.next() + ", ");

		}
		System.out.println("end. ");

	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?