java初级学习总结
} } System.out.println(hashSet.contains(2)); hashSet.clear(); System.out.println("the hashSet's size : " + hashSet.size());
运行结果:
hashSet's info : [red, white, 8, blue, yellow, black]
hashSet : [white, 8, blue, yellow, black]
the size of hashSet is : 5
white 8 blue yellow black
false
the hashSet's size : 0
(2) TreeSet类 对元素排序的有序集合
集合中元素是自然排序,不能有重复元素
例子说明:
import java.util.TreeSet;
import java.util.SortedSet;
public class TreeSetTest {
} public static void main(String args[]){ } SortedSet treeSet = new TreeSet(); treeSet.add("10"); treeSet.add("red"); treeSet.add("yellow"); treeSet.add("blue"); treeSet.add("white"); System.out.println("first_treeSet = " + treeSet.first()); System.out.println("last_treeSet = " + treeSet.last()); // System.out.println("subSet_treeSet = " + treeSet); System.out.println("treeSet'length :" + treeSet.size()); System.out.println("treeSet is Contain red :"+ treeSet.contains("red")); treeSet.clear(); System.out.println(treeSet.isEmpty());
运行结果:
first_treeSet = 10
last_treeSet = yellow
subSet_treeSet = [10, blue, red, white, yellow]
treeSet'length :5
treeSet is Contain red : true
true
其他的构造方法:
java常用集合类详解(有例子,经典呐!!!集合类糊涂的来看啊!!) Collections ...class Student implements Comparable { int num; String name; Student(int num...
Java 中 String 中类的常用方法 1) public String(char [] value):将字符数组转成字符串;//构造方法 char c[]={‘f’,’w’,’s’,’w’,’g’,’...
JAVA程序设计基础 莫乐群 2010年10月 字符串 1 2 3 声明和创建字符串 String类的常用方法 其他字符串处理手段 JAVA程序设计基础 广东交通职业技术学院计算机工程...
Java(第12章Java常用集合 )2011_工学_高等教育_教育专区。JAVA常用类库...{ List<String> allList=new ArrayList<String>(); Collection<String> ...
JAVA中常用的集合类型_计算机软件及应用_IT/计算机_专业资料。JAVA 常用的高级...(String[] args) { // TODO Auto-generated method stub List oneList=new ...
掌握集合类中常用类。 JAVA程序设计与实践教程---王薇主编 教学重点 ? Java...(1)String类:提供了字符串连接、比较、字符 定位、字符串打印等处理方法。 ? ...
_IT/计算机_专业资料。java常用集合类详解Collections Framework 集合框架是一个...String 类实继承了 HashCode()方法. import java.util.*; public class ...
java常用的几种集合_计算机软件及应用_IT/计算机_专业资料。集合类是放在 java...(String[] args) throws java.io.FileNotFoundException { Map word_count_...
? 例如: List<String> ls=new ArrayList<String>(); ls.add(“a1”); ... java中常用的集合类 15页 免费 java集合框架 3页 免费 第9章 Java的集合类...
JAVA集合类应用 12页 免费 java中常用的集合类 15页 免费 java集合类说明 9...= null) { out.println(o);}} public static void main(String[] args) ...
热门文档