您的位置:首页 > 其它

list.isEmpty()和list.size()>0时间复杂度

2017-11-10 10:57 363 查看
List的源码如下所示:(关于Empty和size)

/**
* Returns the number of elements in this list.
*
* @return the number of elements in this list
*/
public int size() {
return size;
}

/**
* Returns <tt>true</tt> if this list contains no elements.
*
* @return <tt>true</tt> if this list contains no elements
*/
public boolean isEmpty() {
return size == 0;
}
如果我要查size时间复杂度是o(n) ,如果是empty o(1);所以判断集合是否为空一般用list.isEmpty()来判断
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  List 时间复杂度
相关文章推荐