List isEmpty()和size()==0 有什么区别

来源:互联网 发布:怪物猎人2g多玩数据库 编辑:程序博客网 时间:2024/05/19 20:45
没有区别,isEmpty()方法也是判断size是否为0.
    /**     * Tests if this list has no elements.     *     * @return  <tt>true</tt> if this list has no elements;     *          <tt>false</tt> otherwise.     */    public boolean isEmpty() {return size == 0;    }

结果都是一样
没什么区别
isEmpty()判断有没有元素
而size()返回有几个元素

如果判断一个集合有无元素 
建议用isEmpty()方法.这清晰,简明
阅读全文
2 0
原创粉丝点击