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

专业做网站费用股票场外期权网站开发

专业做网站费用,股票场外期权网站开发,搭建网站 在线浏览功能,苏州吴中区保洁公司有人说在for循环之前用一个局部变量先获取到list.size()、str.length()#xff0c;然后在for循环的判断条件里通过这个局部变量替换list.size()、str.length()会节省数据计算的时间。事实真的是这样吗#xff1f;下面就为大家解答这个问题。 说明#xff1a;此文章针对Andro…有人说在for循环之前用一个局部变量先获取到list.size()、str.length()然后在for循环的判断条件里通过这个局部变量替换list.size()、str.length()会节省数据计算的时间。事实真的是这样吗下面就为大家解答这个问题。 说明此文章针对Android SDK 进行说明。 List.size() 首先我们看一下List接口我们知道.size()方法是List接口的一个方法返回一个int类型的值。 public interface ListE extends CollectionE {//省略部分代码.../*** 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 ArrayListE extends AbstractListE 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类中的addremove方法中都会动态改变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, ComparableString, 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.hkea.cn/news/14429352/

相关文章:

  • 公司网站建设需要咨询什么问题设计网站有哪些
  • 怎么注销网站seo如何推广网站
  • 两个网站如何做端口映射北京市建设教育协会网站查询
  • 网站代码怎么看唐山市建设交易中心官方网站
  • 建设专业网站公司iis做的网站手机怎么访问
  • 网站开发 报价多网站绑定域名
  • 代做毕业设计网站家具设计郑州专业网站优化
  • 设计做的网站哪些好全英文外贸网站建设
  • 个人网站模板代码百度联盟的网站怎么做
  • 黄山网站建设jidela微信分销系统合法吗
  • 自己做壁纸的网站杭州网站建设外包公司
  • 长春网站建设公司排名长沙网
  • 多语言网站系统网站的营销
  • 邢路桥建设总公司网站爱站网为什么不能用了
  • 建设银行个人官方网站那些做环保网站的好处
  • wordpress安装怎么填镇江网站关键词优化
  • 兰州网站建设方法北京网络营销技术培训
  • 佛山网站建设定制模板下载网站源码
  • 如何把网站放在主机上计算机的专业有哪些
  • 自用电脑做网站青海网站建设公司电话
  • 网站建设基本概述德州做网站最好的公司有哪些
  • 课程网站开发开题报告wordpress 只显示文字
  • 网站内容该怎么做备案网站 cdn
  • 阿里云wordpress建站微信小程序开发快速入门
  • 专门做简历的网站企业网络推广搜索排名
  • 电脑公司网站系统源码站群系统破解版
  • 佛山网站优化宜昌网站模板
  • 021新手学做网站企业网站建设排名价格
  • 怎么推广自己的网站做网站网页需要什么技术
  • 长春网站建设方案详细wordpress注册直接显示密码错误