首页 > 编程知识 正文

c语言fabs用法及代码示例,java基础语法代码示例

时间:2023-05-06 11:37:52 阅读:258526 作者:2932

java.util.Set.isEmpty()方法用于检查Set是否为空。如果Set为空,则返回True,否则返回False。

用法:

boolean isEmpty()

参数:此方法不带任何参数

返回值:如果集合为空,则该方法返回True,否则返回False。

以下示例程序旨在说明java.util.Set.isEmpty()方法:

// Java code to illustrate isEmpty()

import java.io.*;

import java.util.*;

public class SetDemo {

public static void main(String args[])

{

// Creating an empty Set

Set set = new HashSet();

// Use add() method to add elements into the Set

set.add("Welcome");

set.add("To");

set.add("Geeks");

set.add("4");

set.add("Geeks");

// Displaying the Set

System.out.println("Set: " + set);

// Check for the empty set

System.out.println("Is the set empty? " + set.isEmpty());

// Clearing the set using clear() method

set.clear();

// Again Checking for the empty set

System.out.println("Is the set empty? " + set.isEmpty());

}

}

输出:

Set: [4, Geeks, Welcome, To]

Is the set empty? false

Is the set empty? true

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。