当前位置: 首页 > news >正文

响应式网站seowordpress能多人登录

响应式网站seo,wordpress能多人登录,网站公司必须帮备案,wordpress主题怎么修改有人说在for循环之前用一个局部变量先获取到list.size()、str.length(),然后在for循环的判断条件里通过这个局部变量替换list.size()、str.length()会节省数据计算的时间。事实真的是这样吗?下面就为大家解答这个问题。 说明:此文章针对Andro…

有人说在for循环之前用一个局部变量先获取到list.size()、str.length(),然后在for循环的判断条件里通过这个局部变量替换list.size()、str.length()会节省数据计算的时间。事实真的是这样吗?下面就为大家解答这个问题。

说明:此文章针对Android SDK 进行说明。
List.size()

首先我们看一下List接口,我们知道.size()方法是List接口的一个方法,返回一个int类型的值。

public interface List<E> extends Collection<E> {//省略部分代码.../*** Returns the number of elements in this {@code List}.** @return the number of elements in this {@code List}.*/public int size();//省略部分代码...
}



接口中的方法都是没有具体实现的,我们下面看一下List的实现类ArrayList(LinkList也一样,这里讲ArrayList)。我们先看下ArrayList类中的size()方法是如何实现的:
 

public class ArrayList<E> extends AbstractList<E> implements Cloneable, Serializable, RandomAccess {//省略部分代码.../*** Returns the number of elements in this {@code ArrayList}.** @return the number of elements in this {@code ArrayList}.*/@Override public int size() {return size;}//省略部分代码...
}

复制代码



我们看到ArrayList里的size()方法直接return了一个size,通过查看发现size是ArrayList类中的一个int类型的成员变量,代表list结合中的元素数量。
 

    /*** The number of elements in this list.*/int size;



通过跟踪size变量发现在ArrayList类中的add,remove方法中都会动态改变size的大小。
 

复制代码

 /*** Adds the specified object at the end of this {@code ArrayList}.** @param object*            the object to add.* @return always true*/@Override public boolean add(E object) {Object[] a = array;int s = size;if (s == a.length) {Object[] newArray = new Object[s +(s < (MIN_CAPACITY_INCREMENT / 2) ?MIN_CAPACITY_INCREMENT : s >> 1)];System.arraycopy(a, 0, newArray, 0, s);array = a = newArray;}a[s] = object;size = s + 1; // 添加元素size增加modCount++;return true;}
.../*** Removes the object at the specified location from this list.** @param index*            the index of the object to remove.* @return the removed object.* @throws IndexOutOfBoundsException*             when {@code location < 0 || location >= size()}*/@Override public E remove(int index) {Object[] a = array;int s = size;if (index >= s) {throwIndexOutOfBoundsException(index, s);}@SuppressWarnings("unchecked") E result = (E) a[index];System.arraycopy(a, index + 1, a, index, --s - index); //删除元素 size--a[s] = null;  // Prevent memory leaksize = s;modCount++;return result;}

复制代码



通过上述代码我们知道通过ArrayList中的.size()方法获取集合长度,会直接返回一个集合元素数量的变量值,而不会每次调用size()方法都重新计算下集合的元素数量再返回。下面我们在看下String.length()。
String.Length()

我们看下java.lang包下得String类,首先找到String类中的.length()方法:

复制代码

/*** An immutable sequence of UTF-16 {@code char}s.* See {@link Character} for details about the relationship between {@code char} and* Unicode code points.** @see StringBuffer* @see StringBuilder* @see Charset* @since 1.0*/
public final class String implements Serializable, Comparable<String>, CharSequence {//省略部分代码...private final int count;//省略部分代码.../*** Returns the number of {@code char}s in this string. If this string contains surrogate pairs,* this is not the same as the number of code points.*/public int length() {return count;}//省略部分代码...
}

复制代码



我们发现跟ArrayList中的size()方法一样,返回了一个int类型的成员变量count。这个count是怎么赋值的我也不清楚,有兴趣的可以去研究一下。

#总结
综上所述,我们就可以知道List.size()和String.length()方法都是直接返回一个int类型变量值,而不会花费时间再去计算大小后返回,所以放心的去使用size()和length()方法吧。

http://www.yayakq.cn/news/456166/

相关文章:

  • 宁夏网站seo自媒体培训
  • 重庆建设空调网站北京市新闻
  • 推广网站制作怎么做seo优化杭州
  • 建网站做商城个体户资质可以服务营销理论
  • 公司招商型网站建设项目管理的软件有哪些
  • 公司网站首页模板hui怎么做网站
  • wordpress站点做网站需要那些东西
  • 关键词在线挖掘网站个人注册域名和公司注册域名区别
  • 我们网站在那里登陆后台系统管理照片一键生成视频的软件
  • 网站推广公司兴田德润电话多少品牌vi设计方案
  • 相馆网站建设费用预算西安比较厉害的软件公司
  • 网站推广软件推荐前端做任务的网站
  • 如何开始做婚恋网站新能源网站建设
  • 网站多少钱一年用ps怎么做网站首页
  • 如何用ae做模板下载网站宜昌市网站建设
  • 查找网站威海外贸网站建设电话
  • 网站设计流程是文昌网站建设 myvodo
  • 免费建设游戏对战平台网站越秀定制型网站建设
  • 网站建设公司有前途吗企业免费邮箱注册申请
  • 如何做网站编辑代码网站开发涉及到缓存吗
  • spring框架做网站怎么做网页菜单
  • 在网上做黑彩网站会怎样食品经营许可证
  • 营销型网站软件重庆logo设计图片
  • 网站建设捌金手指花总二门户网站的建设方案
  • 招聘企业网站建设模块常用的电子商务网站开发技术
  • 厦门建设企业网站建设工程造价管理
  • 网站做流量怎么赚钱的建设手机版网站
  • 免费1级做爰片在线观看网站投资理财产品网站建设
  • 北京网站seo排名重庆网站建设选承越
  • 站长工具seo下载瑞安外贸网站制作