亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? chap09.htm

?? Thinking in Java, 2nd edition
?? HTM
?? 第 1 頁 / 共 5 頁
字號:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<!--
This document was converted from RTF source: 
By rtftohtml 4.19
See http://www.sunpack.com/RTF
Filename:TIJ2.rtf
Application Directory:C:\TOOLS\RTF2HTML\
Subject:
Author:Bruce Eckel
Operator:Bruce Eckel
Document Comments:
Version Comments:
Comments:
Keywords:
Translation Date:05/21/2001
Translation Time:10:39:12
Translation Platform:Win32
Number of Output files:23
This File:Chap09.htm
SplitDepth=1
SkipNavPanel=1
SkipLeadingToc=1
SkipTrailingToc=1
GenContents=1
GenFrames=1
GenIndex=1
-->
<HEAD lang="en"><META http-equiv="Content-Type" content="text/html">
<TITLE>9: Holding  Your Objects</TITLE>
</HEAD>

<BODY  BGCOLOR="#FFFFFF"><DIV ALIGN="CENTER">
  <a href="http://www.MindView.net">
  <img src="mindview.gif" alt="MindView Inc." BORDER = "0"></a>
  <CENTER>
    <FONT FACE="Verdana" size = "-1">
    [ <a href="README.txt">Viewing Hints</a> ]
    [ <a href="RevHist.htm">Revision History</a> ]
    [ <a href="http://www.mindview.net/Books/TIJ/">Book Home Page</a> ]
    [ <a href="http://www.mindview.net/Etc/MailingList.html">Free Newsletter</a> ] <br>
    [ <a href="http://www.mindview.net/Seminars">Seminars</a> ]
    [ <a href="http://www.mindview.net/CDs">Seminars on CD ROM</a> ]
    [ <a href="http://www.mindview.net/Services">Consulting</a> ]
    </FONT>
  <H2><FONT FACE="Verdana">
  Thinking in Java, 2nd edition, Revision 12</FONT></H2>
  <H3><FONT FACE="Verdana">&copy;2000 by Bruce Eckel</FONT></H3>
  
    <FONT FACE="Verdana" size = "-1">
     [ <a href="Chap08.htm">Previous Chapter</a> ] 
    [ <a href="SimpCont.htm">Short TOC</a> ] 
    [ <a href="Contents.htm">Table of Contents</a> ] 
    [ <a href="DocIdx.htm">Index</a> ]
     [ <a href="Chap10.htm">Next Chapter</a> ] 
    </FONT>
    
  </CENTER>
  </P></DIV><A NAME="_Toc477690729"></A><A NAME="_Toc481064664"></A><A NAME="Heading276"></A><FONT FACE = "Verdana"><H1 ALIGN="LEFT">
9: Holding <BR>Your Objects<A NAME="OLE_LINK2"></A></H1></FONT>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia" SIZE=4><backtalk:display ID=TIJ3_CHAPTER9_I0>
It&#8217;s
a fairly simple program that has only a fixed quantity of objects with known
lifetimes.</FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">In general, your programs will always be
creating new objects based on some criteria that will be known only at the time
the program is running. You won&#8217;t know until run-time the quantity or even
the exact type of the objects you need. To solve the general programming
problem, you need to be able to create any number of objects, anytime, anywhere.
So you can&#8217;t rely on creating a named reference to hold each one of your
objects:</FONT><BR></P></DIV>

<BLOCKQUOTE><FONT SIZE = "+1"><PRE>MyObject myReference;</PRE></FONT></BLOCKQUOTE>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">since you&#8217;ll never know how many of
these you&#8217;ll actually need.

</backtalk:display>
[&nbsp;<a href='http://www.mindview.net/backtalk/CommentServlet?ID=TIJ3_CHAPTER9_I0' 
  target="_blank">Add&nbsp;Comment</a>&nbsp;]

<backtalk:display ID=TIJ3_CHAPTER9_I1>
</FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">To solve this rather essential problem,
Java has several ways to hold objects (or rather, references to objects). The
built-in type is the array, which has been discussed before. Also, the Java
utilities library has a reasonably complete set of
<A NAME="Index848"></A><I>container classes</I> (also known as
<A NAME="Index849"></A><I>collection</I> <I>classes</I>, but because the Java 2
libraries use the name <B>Collection</B> to refer to a particular subset of the
library, I shall use the more inclusive term &#8220;container&#8221;).
Containers provide sophisticated ways to hold and even manipulate your objects.

</backtalk:display>
[&nbsp;<a href='http://www.mindview.net/backtalk/CommentServlet?ID=TIJ3_CHAPTER9_I1' 
  target="_blank">Add&nbsp;Comment</a>&nbsp;]

<backtalk:display ID=TIJ3_CHAPTER9_I2>
</FONT><A NAME="_Toc375545347"></A><A NAME="_Toc481064665"></A><BR></P></DIV>
<A NAME="Heading277"></A><FONT FACE = "Verdana"><H2 ALIGN="LEFT">
Arrays</H2></FONT>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">Most of the necessary introduction to
<A NAME="Index850"></A>arrays is in the last section of Chapter 4, which showed
how you define and initialize an array. Holding objects is the focus of this
chapter, and an array is just one way to hold objects. But there are a number of
other ways to hold objects, so what makes an array special?

</backtalk:display>
[&nbsp;<a href='http://www.mindview.net/backtalk/CommentServlet?ID=TIJ3_CHAPTER9_I2' 
  target="_blank">Add&nbsp;Comment</a>&nbsp;]

<backtalk:display ID=TIJ3_CHAPTER9_I3>
</FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">There are two issues that distinguish
arrays from other types of containers: <A NAME="Index851"></A>efficiency and
<A NAME="Index852"></A>type. The array is the most efficient way that Java
provides to store and randomly access a sequence of objects (actually, object
references). The array is a simple linear sequence, which makes element access
fast, but you pay for this speed: when you create an array object, its size is
fixed and cannot be changed for the lifetime of that array object. You might
suggest creating an array of a particular size and then, if you run out of
space, creating a new one and moving all the references from the old one to the
new one. This is the behavior of the <B>ArrayList </B>class, which will be
studied later in this chapter. However, because of the overhead of this size
flexibility, an <B>ArrayList</B> is measurably less efficient than an array.

</backtalk:display>
[&nbsp;<a href='http://www.mindview.net/backtalk/CommentServlet?ID=TIJ3_CHAPTER9_I3' 
  target="_blank">Add&nbsp;Comment</a>&nbsp;]

<backtalk:display ID=TIJ3_CHAPTER9_I4>
</FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">The <A NAME="Index853"></A><B>vector</B>
container class in C++ <I>does</I> know the type of objects it holds, but it has
a different drawback when compared with arrays in Java: the C++
<B>vector</B>&#8217;s <B>operator[]</B> doesn&#8217;t do bounds checking, so you
can run past the
end</FONT><A NAME="fnB44" HREF="#fn44">[44]</A><FONT FACE="Georgia">. In Java,
you get bounds checking regardless of whether you&#8217;re using an array or a
container&#8212;you&#8217;ll get a
<A NAME="Index854"></A><B>RuntimeException</B> if you exceed the bounds. As
you&#8217;ll learn in Chapter 10, this type of exception indicates a programmer
error, and thus you don&#8217;t need to check for it in your code. As an aside,
the reason the C++ <B>vector</B> doesn&#8217;t check bounds with every access is
speed&#8212;in Java you have the constant performance overhead of bounds
checking all the time for both arrays and containers.

</backtalk:display>
[&nbsp;<a href='http://www.mindview.net/backtalk/CommentServlet?ID=TIJ3_CHAPTER9_I4' 
  target="_blank">Add&nbsp;Comment</a>&nbsp;]

<backtalk:display ID=TIJ3_CHAPTER9_I5>
</FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">The other generic container classes that
will be studied in this chapter, <A NAME="Index855"></A><B>List</B>,
<A NAME="Index856"></A><B>Set</B>, and <A NAME="Index857"></A><B>Map</B>, all
deal with objects as if they had no specific type. That is, they treat them as
type <A NAME="Index858"></A><B>Object</B>, the root class of all classes in
Java. This works fine from one standpoint: you need to build only one container,
and any Java object will go into that container. (Except for
primitives&#8212;these can be placed in containers as constants using the Java
primitive wrapper classes, or as changeable values by wrapping in your own
class.) This is the second place where an array is superior to the generic
containers: when you create an array, you create it to hold a specific type.
This means that you get compile-time type checking to prevent you from putting
the wrong type in, or mistaking the type that you&#8217;re extracting. Of
course, Java will prevent you from sending an inappropriate message to an
object, either at compile-time or at run-time. So it&#8217;s not much riskier
one way or the other, it&#8217;s just nicer if the compiler points it out to
you, faster at run-time, and there&#8217;s less likelihood that the end user
will get surprised by an exception.

</backtalk:display>
[&nbsp;<a href='http://www.mindview.net/backtalk/CommentServlet?ID=TIJ3_CHAPTER9_I5' 
  target="_blank">Add&nbsp;Comment</a>&nbsp;]

<backtalk:display ID=TIJ3_CHAPTER9_I6>
</FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">For efficiency and type checking
it&#8217;s always worth trying to use an array if you can. However, when
you&#8217;re trying to solve a more general problem arrays can be too
restrictive. After looking at arrays, the rest of this chapter will be devoted
to the container classes provided by Java.

</backtalk:display>
[&nbsp;<a href='http://www.mindview.net/backtalk/CommentServlet?ID=TIJ3_CHAPTER9_I6' 
  target="_blank">Add&nbsp;Comment</a>&nbsp;]

<backtalk:display ID=TIJ3_CHAPTER9_I7>
</FONT><A NAME="_Toc375545348"></A><A NAME="_Toc481064666"></A><BR></P></DIV>
<A NAME="Heading278"></A><FONT FACE = "Verdana"><H3 ALIGN="LEFT">
Arrays are first-class
objects<BR><A NAME="Index859"></A><A NAME="Index860"></A></H3></FONT>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">Regardless of what type of array
you&#8217;re working with, the array identifier is actually a reference to a
true object that&#8217;s created on the heap. This is the object that holds the
references to the other objects, and it can be created either implicitly, as
part of the array initialization syntax, or explicitly with a <B>new</B>
expression. Part of the array object (in fact, the only field or method you can
access) is the read-only <B>length</B> member that tells you how many elements
can be stored in that array object.
<A NAME="Index861"></A><A NAME="Index862"></A>The &#8216;<B>[]</B>&#8217; syntax
is the only other access that you have to the array object.

</backtalk:display>
[&nbsp;<a href='http://www.mindview.net/backtalk/CommentServlet?ID=TIJ3_CHAPTER9_I7' 
  target="_blank">Add&nbsp;Comment</a>&nbsp;]

<backtalk:display ID=TIJ3_CHAPTER9_I8>
</FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">The following example shows the various
ways that an array can be initialized, and how the array references can be
assigned to different array objects. It also shows that
<A NAME="Index863"></A>arrays of objects and <A NAME="Index864"></A>arrays of
primitives are almost identical in their use. The only difference is that arrays
of objects hold references, while arrays of primitives hold the primitive values
directly. 
</backtalk:display>
[&nbsp;<a href='http://www.mindview.net/backtalk/CommentServlet?ID=TIJ3_CHAPTER9_I8' 
  target="_blank">Add&nbsp;Comment</a>&nbsp;]

<backtalk:display ID=TIJ3_CHAPTER9_I9>
</FONT><BR></P></DIV>

<BLOCKQUOTE><FONT SIZE = "+1"><PRE><font color=#009900>//: c09:ArraySize.java</font>
<font color=#009900>// Initialization &amp; re-assignment of arrays.</font>

<font color=#0000ff>class</font> Weeble {} <font color=#009900>// A small mythical creature</font>

<font color=#0000ff>public</font> <font color=#0000ff>class</font> ArraySize {
  <font color=#0000ff>public</font> <font color=#0000ff>static</font> <font color=#0000ff>void</font> main(String[] args) {
    <font color=#009900>// Arrays of objects:</font>
    Weeble[] a; <font color=#009900>// Null reference</font>
    Weeble[] b = <font color=#0000ff>new</font> Weeble[5]; <font color=#009900>// Null references</font>
    Weeble[] c = <font color=#0000ff>new</font> Weeble[4];
    <font color=#0000ff>for</font>(<font color=#0000ff>int</font> i = 0; i &lt; c.length; i++)
      c[i] = <font color=#0000ff>new</font> Weeble();
    <font color=#009900>// Aggregate initialization:</font>
    Weeble[] d = { 

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
在线日韩av片| 欧美日韩一区视频| 午夜欧美一区二区三区在线播放| 欧美va在线播放| 色美美综合视频| 国产一区二区免费在线| 亚洲麻豆国产自偷在线| 久久久一区二区三区捆绑**| 91激情五月电影| 国产很黄免费观看久久| 午夜电影一区二区| 国产日韩欧美电影| 91精品国产欧美日韩| 91色乱码一区二区三区| 精品系列免费在线观看| 亚洲高清在线精品| 亚洲天堂免费在线观看视频| 2017欧美狠狠色| 欧美福利电影网| 一本一本大道香蕉久在线精品| 国产在线国偷精品免费看| 亚洲国产精品久久一线不卡| 国产精品国产a| 国产日韩精品一区二区三区| 精品免费国产二区三区 | 蜜臀av在线播放一区二区三区| 中文字幕亚洲在| 久久久99精品久久| 精品国产免费人成电影在线观看四季 | 99精品欧美一区二区三区综合在线| 九色综合国产一区二区三区| 日韩主播视频在线| 亚洲大尺度视频在线观看| 亚洲女性喷水在线观看一区| 中文字幕免费不卡| 欧美国产日韩亚洲一区| 久久新电视剧免费观看| 欧美二区在线观看| 91精品国产综合久久福利| 在线观看日韩国产| 在线观看一区不卡| 欧美亚洲国产怡红院影院| 一本大道av伊人久久综合| 一本久久综合亚洲鲁鲁五月天| 成人av资源在线观看| av一区二区久久| a级高清视频欧美日韩| 99精品久久久久久| 91成人免费电影| 欧美日韩一二三| 69精品人人人人| 精品久久久久久无| 国产欧美日产一区| 国产精品麻豆99久久久久久| 国产精品久久久久久久岛一牛影视| 中文字幕av一区 二区| 亚洲欧洲日韩av| 有坂深雪av一区二区精品| 亚洲国产成人va在线观看天堂| 亚洲国产美国国产综合一区二区| 午夜欧美视频在线观看| 久久精品国产99久久6| 狠狠色丁香久久婷婷综合_中| 国产高清不卡二三区| 99在线视频精品| 欧美亚洲另类激情小说| 日韩午夜精品电影| 久久精品一区二区三区av| 国产精品国产三级国产aⅴ入口 | 爽好久久久欧美精品| 日韩成人一级大片| 国产成人在线看| 色婷婷狠狠综合| 欧美一级视频精品观看| 国产三级精品在线| 亚洲福利视频三区| 激情成人综合网| 一本一道综合狠狠老| 日韩欧美国产不卡| 国产精品久久久久永久免费观看 | 国内精品自线一区二区三区视频| 成人深夜福利app| 欧美调教femdomvk| 精品99一区二区| 亚洲精品国产第一综合99久久| 日韩va亚洲va欧美va久久| av亚洲精华国产精华| 日韩一区二区在线看片| 中文字幕不卡在线| 三级一区在线视频先锋| 国产一区视频在线看| 在线视频你懂得一区| 欧美精品一区二区三区四区| 亚洲精品国久久99热| 国产一区二区三区四区五区美女| 色屁屁一区二区| 久久久久高清精品| 亚洲国产精品综合小说图片区| 丁香婷婷深情五月亚洲| 337p亚洲精品色噜噜噜| ...xxx性欧美| 久草中文综合在线| 欧美专区在线观看一区| 国产欧美一区二区精品忘忧草 | 99精品久久99久久久久| 欧美成人一区二区| 亚洲最大成人网4388xx| 国产一区二区在线观看免费| 精品视频在线视频| 1区2区3区精品视频| 狠狠色丁香婷婷综合久久片| 欧美电影影音先锋| 一区二区三区日韩精品| 国产成人免费视频| 欧美变态口味重另类| 亚洲第一搞黄网站| 日本道在线观看一区二区| 国产清纯白嫩初高生在线观看91 | 肉肉av福利一精品导航| aa级大片欧美| 久久久久97国产精华液好用吗| 亚洲成年人网站在线观看| 97久久精品人人澡人人爽| 久久亚洲精精品中文字幕早川悠里| 五月激情六月综合| 欧洲一区在线电影| 亚洲欧美国产高清| 99久精品国产| 国产精品传媒入口麻豆| 国产精品亚洲第一| 久久久久久97三级| 国产一区二区福利视频| 欧美成人精精品一区二区频| 午夜精品久久久久久久久| 欧美系列亚洲系列| 亚洲18色成人| 欧美蜜桃一区二区三区| 亚洲r级在线视频| 欧美日韩一区二区三区在线看 | 这里只有精品电影| 亚洲国产aⅴ成人精品无吗| 欧美日韩在线播放一区| 亚洲一区在线电影| 欧美日韩的一区二区| 亚洲h动漫在线| 欧美一区二区三区在线电影| 日本伊人午夜精品| 日韩一级片在线播放| 久久99这里只有精品| 精品国精品国产| 国产精品 欧美精品| 国产精品色眯眯| av电影一区二区| 一区二区三区在线视频观看58 | 日韩欧美国产午夜精品| 亚洲三级在线免费| 久久99久久精品| 欧美va日韩va| 国产精品一级黄| 国产精品嫩草久久久久| 91丨porny丨首页| 亚洲一区电影777| 日韩一区二区电影网| 国产精品77777竹菊影视小说| 国产亚洲午夜高清国产拍精品 | 国产高清成人在线| 中文字幕一区二区三区乱码在线 | 午夜视频一区二区| 欧美一级久久久久久久大片| 国产一区日韩二区欧美三区| 国产精品久久夜| 欧美夫妻性生活| 丁香六月综合激情| 一区二区三区四区不卡在线 | 国产欧美日产一区| 在线观看视频91| 国产自产视频一区二区三区| 国产精品久久久久久久岛一牛影视 | 91年精品国产| 日韩av一区二区在线影视| 国产日本亚洲高清| 欧美性感一区二区三区| 国产一区二区剧情av在线| 亚洲精品视频在线| 欧美本精品男人aⅴ天堂| 91网站在线播放| 美女视频一区二区| 一区二区三区国产精华| 精品国产一区二区三区久久影院| av电影在线观看一区| 久久电影国产免费久久电影| 亚洲欧美福利一区二区| 久久日韩粉嫩一区二区三区| 在线精品视频免费观看| 国产成人久久精品77777最新版本| 亚洲国产成人porn| 日韩理论片在线| 欧美精品一区二区三区蜜桃 | 尤物在线观看一区| 久久久久久久久久久久久久久99|