iis服务器助手广告广告
返回顶部
首页 > 资讯 > 精选 >TreeSet怎么在Java中使用
  • 661
分享到

TreeSet怎么在Java中使用

2023-06-06 13:06:44 661人浏览 八月长安
摘要

本文章向大家介绍TreeSet怎么在Java中使用,主要包括TreeSet怎么在Java中使用的使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。Java可以用来干什么Java主要应用于:1. w

本文章向大家介绍TreeSet怎么在Java中使用,主要包括TreeSet怎么在Java中使用的使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

Java可以用来干什么

Java主要应用于:1. web开发;2. Android开发;3. 客户端开发;4. 网页开发;5. 企业级应用开发;6. Java大数据开发;7.游戏开发等。

TreeSet简介

TreeSet 是一个有序的集合,它的作用是提供有序的Set集合。它继承于AbstractSet抽象类,实现了NavigableSet<E>, Cloneable, java.io.Serializable接口。

TreeSet 继承于AbstractSet,所以它是一个Set集合,具有Set的属性和方法。

TreeSet 实现了NavigableSet接口,意味着它支持一系列的导航方法。比如查找与指定目标最匹配项。

TreeSet 实现了Cloneable接口,意味着它能被克隆。

TreeSet 实现了java.io.Serializable接口,意味着它支持序列化。

TreeSet是基于TreeMap实现的。TreeSet中的元素支持2种排序方式:自然排序 或者 根据创建TreeSet 时提供的 Comparator 进行排序。这取决于使用的构造方法。

TreeSet为基本操作(add、remove 和 contains)提供受保证的 log(n) 时间开销。

另外,TreeSet是非同步的。 它的iterator 方法返回的迭代器是fail-fast的。

TreeSet的构造函数

// 默认构造函数。使用该构造函数,TreeSet中的元素按照自然排序进行排列。TreeSet()// 创建的TreeSet包含collectionTreeSet(Collection<? extends E> collection)// 指定TreeSet的比较器TreeSet(Comparator<? super E> comparator)// 创建的TreeSet包含setTreeSet(SortedSet<E> set)TreeSet的apiboolean   add(E object)boolean   addAll(Collection<? extends E> collection)void   clear()Object   clone()boolean   contains(Object object)E    first()boolean   isEmpty()E    last()E    pollFirst()E    pollLast()E    lower(E e)E    floor(E e)E    ceiling(E e)E    higher(E e)boolean   remove(Object object)int   size()Comparator<? super E> comparator()Iterator<E>  iterator()Iterator<E>  descendingiterator()SortedSet<E>  headSet(E end)NavigableSet<E>  descendingSet()NavigableSet<E>  headSet(E end, boolean endInclusive)SortedSet<E>  subSet(E start, E end)NavigableSet<E>  subSet(E start, boolean startInclusive, E end, boolean endInclusive)NavigableSet<E>  tailSet(E start, boolean startInclusive)SortedSet<E>  tailSet(E start)

说明:

(01) TreeSet是有序的Set集合,因此支持add、remove、get等方法。

(02) 和NavigableSet一样,TreeSet的导航方法大致可以区分为两类,一类时提供元素项的导航方法,返回某个元素;另一类时提供集合的导航方法,返回某个集合。

lower、floor、ceiling 和 higher 分别返回小于、小于等于、大于等于、大于给定元素的元素,如果不存在这样的元素,则返回 null。

第2部分 TreeSet数据结构

TreeSet的继承关系

java.lang.Object ↳ java.util.AbstractCollection<E>  ↳ java.util.AbstractSet<E>  ↳ java.util.TreeSet<E>public class TreeSet<E> extends AbstractSet<E>  implements NavigableSet<E>, Cloneable, java.io.Serializable{}

TreeSet与Collection关系如下图:

TreeSet怎么在Java中使用

从图中可以看出:

(01) TreeSet继承于AbstractSet,并且实现了NavigableSet接口。

(02) TreeSet的本质是一个"有序的,并且没有重复元素"的集合,它是通过TreeMap实现的。TreeSet中含有一个"NavigableMap类型的成员变量"m,而m实际上是"TreeMap的实例"。

第3部分 TreeSet源码解析(基于jdk1.6.0_45)

为了更了解TreeSet的原理,下面对TreeSet源码代码作出分析。

 package java.util;  public class TreeSet<E> extends AbstractSet<E> implements NavigableSet<E>, Cloneable, java.io.Serializable { // NavigableMap对象 private transient NavigableMap<E,Object> m;  // TreeSet是通过TreeMap实现的, // PRESENT是键-值对中的值。 private static final Object PRESENT = new Object(); // 不带参数的构造函数。创建一个空的TreeMap public TreeSet() { this(new TreeMap<E,Object>()); } // 将TreeMap赋值给 "NavigableMap对象m" TreeSet(NavigableMap<E,Object> m) { this.m = m; } // 带比较器的构造函数。 public TreeSet(Comparator<? super E> comparator) { this(new TreeMap<E,Object>(comparator)); } // 创建TreeSet,并将集合c中的全部元素都添加到TreeSet中 public TreeSet(Collection<? extends E> c) { this(); // 将集合c中的元素全部添加到TreeSet中 addAll(c); } // 创建TreeSet,并将s中的全部元素都添加到TreeSet中 public TreeSet(SortedSet<E> s) { this(s.comparator()); addAll(s); } // 返回TreeSet的顺序排列的迭代器。 // 因为TreeSet时TreeMap实现的,所以这里实际上时返回TreeMap的“键集”对应的迭代器 public Iterator<E> iterator() { return m.navigableKeySet().iterator(); } // 返回TreeSet的逆序排列的迭代器。 // 因为TreeSet时TreeMap实现的,所以这里实际上时返回TreeMap的“键集”对应的迭代器 public Iterator<E> descendingIterator() { return m.descendingKeySet().iterator(); } // 返回TreeSet的大小 public int size() { return m.size(); } // 返回TreeSet是否为空 public boolean isEmpty() { return m.isEmpty(); } // 返回TreeSet是否包含对象(o) public boolean contains(Object o) { return m.containsKey(o); } // 添加e到TreeSet中 public boolean add(E e) { return m.put(e, PRESENT)==null; } // 删除TreeSet中的对象o public boolean remove(Object o) { return m.remove(o)==PRESENT; } // 清空TreeSet public void clear() { m.clear(); } // 将集合c中的全部元素添加到TreeSet中 public boolean addAll(Collection<? extends E> c) { // Use linear-time version if applicable if (m.size()==0 && c.size() > 0 &&  c instanceof SortedSet &&  m instanceof TreeMap) {  SortedSet<? extends E> set = (SortedSet<? extends E>) c;  TreeMap<E,Object> map = (TreeMap<E, Object>) m;  Comparator<? super E> cc = (Comparator<? super E>) set.comparator();  Comparator<? super E> mc = map.comparator();  if (cc==mc || (cc != null && cc.equals(mc))) {  map.addAllForTreeSet(set, PRESENT);  return true;  } } return super.addAll(c); }  // 返回子Set,实际上是通过TreeMap的subMap()实现的。 public NavigableSet<E> subSet(E fromElement, boolean fromInclusive,     E toElement, boolean toInclusive) {  return new TreeSet<E>(m.subMap(fromElement, fromInclusive,     toElement, toInclusive)); }  // 返回Set的头部,范围是:从头部到toElement。 // inclusive是是否包含toElement的标志 public NavigableSet<E> headSet(E toElement, boolean inclusive) {  return new TreeSet<E>(m.headMap(toElement, inclusive)); }  // 返回Set的尾部,范围是:从fromElement到结尾。 // inclusive是是否包含fromElement的标志 public NavigableSet<E> tailSet(E fromElement, boolean inclusive) {  return new TreeSet<E>(m.tailMap(fromElement, inclusive)); }  // 返回子Set。范围是:从fromElement(包括)到toElement(不包括)。 public SortedSet<E> subSet(E fromElement, E toElement) {  return subSet(fromElement, true, toElement, false); }  // 返回Set的头部,范围是:从头部到toElement(不包括)。 public SortedSet<E> headSet(E toElement) {  return headSet(toElement, false); }  // 返回Set的尾部,范围是:从fromElement到结尾(不包括)。 public SortedSet<E> tailSet(E fromElement) {  return tailSet(fromElement, true); }  // 返回Set的比较器 public Comparator<? super E> comparator() {  return m.comparator(); }  // 返回Set的第一个元素 public E first() {  return m.firsTKEy(); }  // 返回Set的最后一个元素 public E first() { public E last() {  return m.lastKey(); }  // 返回Set中小于e的最大元素 public E lower(E e) {  return m.lowerKey(e); }  // 返回Set中小于/等于e的最大元素 public E floor(E e) {  return m.floorKey(e); }  // 返回Set中大于/等于e的最小元素 public E ceiling(E e) {  return m.ceilingKey(e); }  // 返回Set中大于e的最小元素 public E higher(E e) {  return m.higherKey(e); }  // 获取第一个元素,并将该元素从TreeMap中删除。 public E pollFirst() {  Map.Entry<E,?> e = m.pollFirstEntry();  return (e == null)? null : e.getKey(); }  // 获取最后一个元素,并将该元素从TreeMap中删除。 public E pollLast() {  Map.Entry<E,?> e = m.pollLastEntry();  return (e == null)? null : e.getKey(); }  // 克隆一个TreeSet,并返回Object对象 public Object clone() {  TreeSet<E> clone = null;  try {  clone = (TreeSet<E>) super.clone();  } catch (CloneNotSupportedException e) {  throw new InternalError();  }   clone.m = new TreeMap<E,Object>(m);  return clone; }  // java.io.Serializable的写入函数 // 将TreeSet的“比较器、容量,所有的元素值”都写入到输出流中 private void writeObject(java.io.ObjectOutputStream s)  throws java.io.IOException {  s.defaultWriteObject();   // 写入比较器  s.writeObject(m.comparator());   // 写入容量  s.writeInt(m.size());   // 写入“TreeSet中的每一个元素”  for (Iterator i=m.keySet().iterator(); i.hasNext(); )  s.writeObject(i.next()); }  // java.io.Serializable的读取函数:根据写入方式读出 // 先将TreeSet的“比较器、容量、所有的元素值”依次读出 private void readObject(java.io.ObjectInputStream s)  throws java.io.IOException, ClassNotFoundException {  // Read in any hidden stuff  s.defaultReadObject();   // 从输入流中读取TreeSet的“比较器”  Comparator<? super E> c = (Comparator<? super E>) s.readObject();   TreeMap<E,Object> tm;  if (c==null)  tm = new TreeMap<E,Object>();  else  tm = new TreeMap<E,Object>(c);  m = tm;   // 从输入流中读取TreeSet的“容量”  int size = s.readInt();   // 从输入流中读取TreeSet的“全部元素”  tm.readTreeSet(size, s, PRESENT); }  // TreeSet的序列版本号 private static final long serialVersionUID = -2479143000061671589L; }

总结:

(01) TreeSet实际上是TreeMap实现的。当我们构造TreeSet时;若使用不带参数的构造函数,则TreeSet的使用自然比较器;若用户需要使用自定义的比较器,则需要使用带比较器的参数。

(02) TreeSet是非线程安全的。

(03) TreeSet实现java.io.Serializable的方式。当写入到输出流时,依次写入“比较器、容量、全部元素”;当读出输入流时,再依次读取。

第4部分 TreeSet遍历方式

4.1 Iterator顺序遍历

for(Iterator iter = set.iterator(); iter.hasNext(); ) {  iter.next();}

4.2 Iterator顺序遍历

// 假设set是TreeSet对象for(Iterator iter = set.descendingIterator(); iter.hasNext(); ) {  iter.next();}

4.3 for-each遍历HashSet

// 假设set是TreeSet对象,并且set中元素是String类型String[] arr = (String[])set.toArray(new String[0]);for (String str:arr) System.out.printf("for each : %s\n", str);

TreeSet不支持快速随机遍历,只能通过迭代器进行遍历!

TreeSet遍历测试程序如下:

 import java.util.*;   public class TreeSetIteratorTest {  public static void main(String[] args) {  TreeSet set = new TreeSet();  set.add("aaa");  set.add("aaa");  set.add("bbb");  set.add("eee");  set.add("DDD");  set.add("ccc");   // 顺序遍历TreeSet  ascIteratorThroughIterator(set) ;  // 逆序遍历TreeSet  descIteratorThroughIterator(set);  // 通过for-each遍历TreeSet。不推荐!此方法需要先将Set转换为数组  foreachTreeSet(set); }  // 顺序遍历TreeSet public static void ascIteratorThroughIterator(TreeSet set) {  System.out.print("\n ---- Ascend Iterator ----\n");  for(Iterator iter = set.iterator(); iter.hasNext(); ) {  System.out.printf("asc : %s\n", iter.next());  } }  // 逆序遍历TreeSet public static void descIteratorThroughIterator(TreeSet set) {  System.out.printf("\n ---- Descend Iterator ----\n");  for(Iterator iter = set.descendingIterator(); iter.hasNext(); )  System.out.printf("desc : %s\n", (String)iter.next()); }  // 通过for-each遍历TreeSet。不推荐!此方法需要先将Set转换为数组 private static void foreachTreeSet(TreeSet set) {  System.out.printf("\n ---- For-each ----\n");  String[] arr = (String[])set.toArray(new String[0]);  for (String str:arr)  System.out.printf("for each : %s\n", str); } }

运行结果:

---- Ascend Iterator ----asc : aaaasc : bbbasc : cccasc : dddasc : eee---- Descend Iterator ----desc : eeedesc : ddddesc : cccdesc : bbbdesc : aaa---- For-each ----for each : aaafor each : bbbfor each : cccfor each : dddfor each : eee

第5部分 TreeSet示例

下面通过实例学习如何使用TreeSet

import java.util.*;public class TreeSetTest { public static void main(String[] args) { testTreeSetAPIs(); }  // 测试TreeSet的api public static void testTreeSetAPIs() { String val; // 新建TreeSet TreeSet tSet = new TreeSet(); // 将元素添加到TreeSet中 tSet.add("aaa"); // Set中不允许重复元素,所以只会保存一个“aaa” tSet.add("aaa"); tSet.add("bbb"); tSet.add("eee"); tSet.add("ddd"); tSet.add("ccc"); System.out.println("TreeSet:"+tSet); // 打印TreeSet的实际大小 System.out.printf("size : %d\n", tSet.size()); // 导航方法 // floor(小于、等于) System.out.printf("floor bbb: %s\n", tSet.floor("bbb")); // lower(小于) System.out.printf("lower bbb: %s\n", tSet.lower("bbb")); // ceiling(大于、等于) System.out.printf("ceiling bbb: %s\n", tSet.ceiling("bbb")); System.out.printf("ceiling eee: %s\n", tSet.ceiling("eee")); // ceiling(大于) System.out.printf("higher bbb: %s\n", tSet.higher("bbb")); // subSet() System.out.printf("subSet(aaa, true, ccc, true): %s\n", tSet.subSet("aaa", true, "ccc", true)); System.out.printf("subSet(aaa, true, ccc, false): %s\n", tSet.subSet("aaa", true, "ccc", false)); System.out.printf("subSet(aaa, false, ccc, true): %s\n", tSet.subSet("aaa", false, "ccc", true)); System.out.printf("subSet(aaa, false, ccc, false): %s\n", tSet.subSet("aaa", false, "ccc", false)); // headSet() System.out.printf("headSet(ccc, true): %s\n", tSet.headSet("ccc", true)); System.out.printf("headSet(ccc, false): %s\n", tSet.headSet("ccc", false)); // tailSet() System.out.printf("tailSet(ccc, true): %s\n", tSet.tailSet("ccc", true)); System.out.printf("tailSet(ccc, false): %s\n", tSet.tailSet("ccc", false)); // 删除“ccc” tSet.remove("ccc"); // 将Set转换为数组 String[] arr = (String[])tSet.toArray(new String[0]); for (String str:arr)  System.out.printf("for each : %s\n", str); // 打印TreeSet System.out.printf("TreeSet:%s\n", tSet); // 遍历TreeSet for(Iterator iter = tSet.iterator(); iter.hasNext(); ) {  System.out.printf("iter : %s\n", iter.next()); } // 删除并返回第一个元素 val = (String)tSet.pollFirst(); System.out.printf("pollFirst=%s, set=%s\n", val, tSet); // 删除并返回最后一个元素 val = (String)tSet.pollLast(); System.out.printf("pollLast=%s, set=%s\n", val, tSet); // 清空HashSet tSet.clear(); // 输出HashSet是否为空 System.out.printf("%s\n", tSet.isEmpty()?"set is empty":"set is not empty"); }}

运行结果:

TreeSet:[aaa, bbb, ccc, ddd, eee]size : 5floor bbb: bbblower bbb: aaaceiling bbb: bbbceiling eee: eeehigher bbb: cccsubSet(aaa, true, ccc, true): [aaa, bbb, ccc]subSet(aaa, true, ccc, false): [aaa, bbb]subSet(aaa, false, ccc, true): [bbb, ccc]subSet(aaa, false, ccc, false): [bbb]headSet(ccc, true): [aaa, bbb, ccc]headSet(ccc, false): [aaa, bbb]tailSet(ccc, true): [ccc, ddd, eee]tailSet(ccc, false): [ddd, eee]for each : aaafor each : bbbfor each : dddfor each : eeeTreeSet:[aaa, bbb, ddd, eee]iter : aaaiter : bbbiter : ddditer : eeepollFirst=aaa, set=[bbb, ddd, eee]pollLast=eee, set=[bbb, ddd]set is empty

补充:Java中关于使用TreeSet存储数据的自然排序和定制排序

一、题目

创建类的 5 个对象,并把这些对象放入 TreeSet 集合中(TreeSet 需使用泛型和不用泛型分别来定义)

分别按以下两种方式对集合中的元素进行排序,并遍历输出:

使 Employee 实现 Comparable 接口,并按 name 排序

创建 TreeSet 时传入 Comparator 对象,按生日日期的先后排序。

二、定义一个 Employee 类

public class Employee implements Comparable<Employee> { private String name; private int age; private MyDate birthday; public Employee() { } public Employee(String name, int age, MyDate birthday) {  this.name = name;  this.age = age;  this.birthday = birthday; } public String getName() {  return name; } public void setName(String name) {  this.name = name; } public int getAge() {  return age; } public void setAge(int age) {  this.age = age; } public MyDate getBirthday() {  return birthday; } public void setBirthday(MyDate birthday) {  this.birthday = birthday; } @Override public String toString() {  return "Employee{" +    "name='" + name + '\'' +    ", age=" + age +    ", birthday=" + birthday +    '}'; }  //不用泛型// @Override// public int compareTo(Object o) {//  if(o instanceof Employee){//   Employee employee = (Employee) o;//   return this.name.compareTo(employee.name);//  }//  throw new RuntimeException("输入的数据类型不一致");// }  //使用泛型 @Override public int compareTo(Employee o) {  return this.name.compareTo(o.name); }}

三、MyDate 类

public class MyDate implements Comparable<MyDate> { private int year; private int month; private int day; public MyDate() { } public MyDate(int year, int month, int day) {  this.year = year;  this.month = month;  this.day = day; } @Override public String toString() {  return "MyDate{" +    "year=" + year +    ", month=" + month +    ", day=" + day +    '}'; } public int getYear() {  return year; } public void setYear(int year) {  this.year = year; } public int getMonth() {  return month; } public void setMonth(int month) {  this.month = month; } public int getDay() {  return day; } public void setDay(int day) {  this.day = day; } @Override public int compareTo(MyDate o) {  int minusYear= this.year-o.year;  if (minusYear !=0){   return minusYear;  }  int minusMonth= this.month-o.month;  if (minusMonth !=0){   return minusMonth;  }  return this.day-o.day; }}

四、单元测试

(一)

@Test public void test1(){  TreeSet<Employee> set = new TreeSet<>();  set.add(new Employee("hh",23,new MyDate(1992,4,12)));  set.add(new Employee("ff",43,new MyDate(1956,5,4)));  set.add(new Employee("aa",27,new MyDate(1936,8,6)));  set.add(new Employee("gg",38,new MyDate(1992,4,4)));  Iterator<Employee> iterator = set.iterator();  while (iterator.hasNext()){   System.out.println(iterator.next());  } }

结果如下:

TreeSet怎么在Java中使用

(二)

 @Test public void test2(){  TreeSet<Employee> set = new TreeSet<>(new Comparator<Employee>() {   @Override   public int compare(Employee e1, Employee e2) {    //加上泛型    MyDate b1 = e1.getBirthday();    MyDate b2 = e2.getBirthday();    return b1.compareTo(b2);    //不加泛型//    if (o1 instanceof Employee && o2 instanceof Employee){//     Employee m1 = (Employee) o1;//     Employee m2 = (Employee) o2;//     MyDate m1Birthday = m1.getBirthday();//     MyDate m2Birthday = m2.getBirthday();////     int minusYear = m1Birthday.getYear()- m2Birthday.getYear();//     if (minusYear!=0){//      return minusYear;//     }//     int minusMonth = m1Birthday.getMonth()- m2Birthday.getMonth();//     if (minusMonth!=0){//      return minusMonth;//     }//     int minusDay = m1Birthday.getDay()- m2Birthday.getDay();//     return minusDay;////    }//    throw new RuntimeException("传入的数据类型不一致");   }  });  set.add(new Employee("hh",23,new MyDate(1944,12,4)));  set.add(new Employee("ff",43,new MyDate(1957,5,4)));  set.add(new Employee("aa",27,new MyDate(1906,12,6)));  set.add(new Employee("gg",38,new MyDate(1906,4,4)));  Iterator<Employee> iterator = set.iterator();  while (iterator.hasNext()){   System.out.println(iterator.next());  } }

结果如下:

TreeSet怎么在Java中使用

到此这篇关于TreeSet怎么在Java中使用的文章就介绍到这了,更多相关的内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!

--结束END--

本文标题: TreeSet怎么在Java中使用

本文链接: https://www.lsjlt.com/news/247085.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • TreeSet怎么在Java中使用
    本文章向大家介绍TreeSet怎么在Java中使用,主要包括TreeSet怎么在Java中使用的使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。Java可以用来干什么Java主要应用于:1. w...
    99+
    2023-06-06
  • java中TreeSet怎么使用
    TreeSet是Java中的一个实现了SortedSet接口的集合类,它是一个有序的集合,底层使用红黑树(Red-Black tre...
    99+
    2023-08-08
    java TreeSet
  • Java之TreeSet怎么使用
    TreeSet是一种有序的集合,它基于红黑树实现。以下是使用TreeSet的一些常见操作:1. 创建一个TreeSet对象:```j...
    99+
    2023-09-16
    Java TreeSet
  • 在Java中如何正确的使用TreeSet
    这期内容当中小编将会给大家带来有关在Java中如何正确的使用TreeSet,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。TreeSet简介TreeSet 是一个有序的集合,它的作用是提供有序的Set集合。...
    99+
    2023-05-31
    java treeset ava
  • Java集合HashSet,TreeSet与LinkedHashSet怎么使用
    本篇内容介绍了“Java集合HashSet,TreeSet与LinkedHashSet怎么使用”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!...
    99+
    2023-06-02
  • HashSet与TreeSet在Java中有什么不同
    本篇文章给大家分享的是有关HashSet与TreeSet在Java中有什么不同,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。1. HashSetHashSet有以下特点:不能保...
    99+
    2023-05-31
    java hashset treeset
  • Java中TreeSet的作用是什么
    TreeSet是Java集合框架中的一种集合实现类,它实现了SortedSet接口,可以存储有序的、不重复的元素。TreeSet的作...
    99+
    2023-09-09
    Java TreeSet
  • 怎么在Java中对TreeSet进行自定义类型的排序
    怎么在Java中对TreeSet进行自定义类型的排序?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。Java可以用来干什么Java主要应用于:1. web开发;2. Androi...
    99+
    2023-06-06
  • TreeSet的使用方法是什么
    TreeSet是Java中的一个集合类,它实现了Set接口,用于保存一组元素并且保持这些元素的顺序。TreeSet使用红黑树(Red...
    99+
    2024-03-08
    TreeSet
  • HashSet/TreeSet是怎么使用hashCode()和equal()方法的
    本篇内容主要讲解“HashSet/TreeSet是怎么使用hashCode()和equal()方法的”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“HashSet/TreeSet是怎么使用hash...
    99+
    2023-06-03
  • string在java中怎么使用
    在Java中,字符串(String)是一个类,用于表示文本数据。你可以使用字符串类型来存储和操作文本。以下是一些在Java中使用字符...
    99+
    2023-09-25
    string java
  • ArrayList在java中怎么使用
    在Java中,ArrayList是一种动态数组,可以存储任意类型的对象。以下是使用ArrayList的一些常见操作:1. 导入Arr...
    99+
    2023-09-28
    java ArrayList
  • SelectableChannel怎么在java中使用
    这期内容当中小编将会给大家带来有关SelectableChannel怎么在java中使用,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。1、说明(1)SelectableChannel 是一个抽象类,它实现...
    99+
    2023-06-14
  • Future怎么在java中使用
    Future怎么在java中使用?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。Java的特点有哪些Java的特点有哪些1.Java语言作为静态面向对象编程语言的代表,实现了...
    99+
    2023-06-14
  • HashSet怎么在java中使用
    HashSet怎么在java中使用?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。Java是什么Java是一门面向对象编程语言,可以编写桌面应用程序、Web应用程序、分布式系统和...
    99+
    2023-06-14
  • LocalTime怎么在java中使用
    LocalTime怎么在java中使用?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。Java是什么Java是一门面向对象编程语言,可以编写桌面应用程序、Web应用程序、分布...
    99+
    2023-06-14
  • notifyall怎么在java中使用
    今天就跟大家聊聊有关notifyall怎么在java中使用,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。Java可以用来干什么Java主要应用于:1. web开发;2. Androi...
    99+
    2023-06-14
  • short怎么在java中使用
    这篇文章将为大家详细讲解有关short怎么在java中使用,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。Java的特点有哪些Java的特点有哪些1.Java语言作为静态面向对象编程语言的代表...
    99+
    2023-06-14
  • 怎么在java中使用float
    本篇文章给大家分享的是有关怎么在java中使用float,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。Java有哪些集合类Java中的集合主要分为四类:1、List列表:有序的...
    99+
    2023-06-14
  • Switch怎么在Java中使用
    Switch怎么在Java中使用?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。一、java当中的switch与C#相比有以下区别注:在java中switch后的表达式的类型只能...
    99+
    2023-05-30
    java switch
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作