Arraylist class: Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (Created page with "<!-- Arraylist class --> Arraylists can be thought of as traditional arrays with no bounds and much more flexibility. For background information about collections and Arraylist...")
 
mNo edit summary
Line 2: Line 2:
Arraylists can be thought of as traditional arrays with no bounds and
Arraylists can be thought of as traditional arrays with no bounds and
much more flexibility.
much more flexibility.
 
For background information about collections and Arraylists and about
declaring Arraylist object variables,
see [[Collections]].
See also [[Collections#Coding considerations for collections|Coding
considerations for collections]].
The following code illustrates several of the Arraylist methods:
The following code illustrates several of the Arraylist methods:
<pre style="xmp">
<p class="code">
    %alist  is collection Arraylist of longstring
%alist  is collection Arraylist of longstring
    %i      is float
%i      is float
   
   
    %alist = new
%alist = new
    %alist:add('Idle')
%alist:add('Idle')
    %alist:add('Gumby')
%alist:add('Gumby')
    %alist:add('Chapman')
%alist:add('Chapman')
    %alist:add('Pallin')
%alist:add('Pallin')
    %alist:insert(2, 'Jones')
%alist:insert(2, 'Jones')
    %alist:removeItem(4)
%alist:removeItem(4)
    %alist(3) = 'Cleese'
%alist(3) = 'Cleese'
    for %i from 1 to %alist:count
for %i from 1 to %alist:count
        print %alist(%i)
  print %alist(%i)
    end for
end for
</pre>
</p>
This code snippet would print:
This code snippet would print:
<pre style="xmp">
<p class="output">
    Idle
Idle
    Jones
Jones
    Cleese
Cleese
    Pallin
Pallin
</pre>
</p>
   
   
The individual Arraylist methods are described in the following subsections.
The individual <var>Arraylist<var> methods are described in the following subsections.
In the method templates, <tt>%arrayl</tt> is used to represent the object
In the method templates, <var class="term">al</var> is used to represent the object
to which the method is being applied, sometimes called the &ldquo;method
to which the method is being applied, sometimes called the "method object"
object&rdquo;
or the "method Arraylist".
or the &ldquo;method Arraylist.&rdquo;
Additional conventions are described in [[Notation conventions for methods]].
Additional conventions are described in [[Notation conventions for methods]].
==See also==
<table>
<tr><th>[[List of Arraylist methods]]</th>
<td>For a list of all methods in the Arraylist class, with a brief description of each.</td></tr>
<tr><th>[[Collections]]</th>
<td>For background information about collections and <var>Arraylist</var>s and about
declaring <var>Arraylist</var> object variables.</td></tr>
<tr><th>[[Collections#Coding considerations for collections|Coding
considerations for collections]]</th>
<td>For tips on using collections.</td></tr>
</table>
[[Category:System classes]]
[[Category:System classes]]

Revision as of 11:57, 27 January 2011

Arraylists can be thought of as traditional arrays with no bounds and much more flexibility.

The following code illustrates several of the Arraylist methods:

%alist is collection Arraylist of longstring %i is float %alist = new %alist:add('Idle') %alist:add('Gumby') %alist:add('Chapman') %alist:add('Pallin') %alist:insert(2, 'Jones') %alist:removeItem(4) %alist(3) = 'Cleese' for %i from 1 to %alist:count print %alist(%i) end for

This code snippet would print:

Idle Jones Cleese Pallin

The individual Arraylist methods are described in the following subsections. In the method templates, al is used to represent the object to which the method is being applied, sometimes called the "method object" or the "method Arraylist". Additional conventions are described in Notation conventions for methods.

See also

List of Arraylist methods For a list of all methods in the Arraylist class, with a brief description of each.
Collections For background information about collections and Arraylists and about declaring Arraylist object variables.
Coding considerations for collections For tips on using collections.