Creating an Array: Difference between revisions

From Rosetta Code
Content added Content deleted
mNo edit summary
(revert spam)
Line 1: Line 1:
{{task}}
[http://getraylo.freeweb7.com/img/styles/lg-.htm lg 17 pollici lcd] [http://mauballe.125mb.com/web/mouse-trackball/ mouse trackball] [http://flheddin.125mb.com/content/view/ristorante-africano.htm ristorante africano] [http://mauballe.125mb.com/web/lavatrice-cm/ lavatrice cm 40] [http://flheddin.125mb.com/content/view/croatian-rhapsody.htm croatian rhapsody] [http://www.freewebtown.com/starbriteyellow/resources/articles/opa-opa.htm opa opa version spanish] [http://scaleslea.freewebpage.org/text/directory/iluminati/ iluminati] [http://huruple.125mb.com/text/directory/ibanez-tcm/ ibanez tcm50] [http://selemku.t35.com/text/directory/toner.htm toner 3522] [http://licohwar.homeblock.com/library/html/lettere-presentazione/ lettere presentazione curriculum vitae] [http://beshennayabelka.freehostia.com/content/view/schede-video.htm schede video dual head pci] [http://mcwardlo.t35.com/library/html/webranking/ webranking] [http://zoelverd.freeweb7.com/description/lib/fake-sexy/ fake sexy] [http://saline-joy.freehostia.com/web/deha.htm deha] [http://www.freewebtown.com/boogiejames/topic/la-provincia.htm la provincia di napoli] [http://lorcaxon.homeblock.com/data/toner/ toner 1210] [http://getraylo.freeweb7.com/img/styles/ritter-hellmut.htm ritter, hellmut] [http://lorcaxon.homeblock.com/data/gay-sesso/ gay sesso video] [http://selemku.t35.com/text/directory/www-googo.htm www googo com] [http://greensticky.freehostia.com/library/html/mc-and/ mc and gregory] [http://licohwar.homeblock.com/library/html/plasma-/ plasma 37 samsung] [http://www.freewebtown.com/boogiejames/topic/inspire-t.htm inspire t3000] [http://selemku.t35.com/text/directory/yogioh.htm yo-gi-oh] [http://www.freewebtown.com/prncessprncipe/library/html/footjob.htm footjob] [http://selemku.t35.com/text/directory/www-tele.htm www tele tutto it] [http://mcwardlo.t35.com/library/html/sean-pul/ sean pul] [http://www.freewebtown.com/boogiejames/topic/viaccess-keys.htm viaccess keys astra] [http://flheddin.125mb.com/content/view/lcd-.htm lcd 5 dvd lettori e divx] [http://lorcaxon.homeblock.com/data/palmare-treo/ palmare treo 650] [http://benevolently.freehostia.com/content/view/goca-bozinovska/ goca bozinovska] [http://lorcaxon.homeblock.com/data/project-pitchfork/ project pitchfork. live 2003] [http://beshennayabelka.freehostia.com/content/view/plc-logo.htm plc logo siemens] [http://wainfan.t35.com/view/new/una-donna.htm una donna di notte] [http://mcwardlo.t35.com/library/html/www-fastfurios/ www 2fast2furios it] [http://www.freewebtown.com/prncessprncipe/library/html/idc.htm idc] [http://lorcaxon.homeblock.com/data/vuela/ vuela] [http://www.freewebtown.com/starbriteyellow/resources/articles/lacie-big.htm lacie big disk 500 gb] [http://failtoexpress.freehostia.com/html/linus-radio.htm linus radio deejay] [http://www.freewebtown.com/boogiejames/topic/alloggi-istituti.htm alloggi istituti padova] [http://greensticky.freehostia.com/library/html/poli-gest/ poli gest sas] [http://getm0ney.freewebpage.org/lib/quota-periscopio/ quota periscopio] [http://benevolently.freehostia.com/content/view/soluzione-the/ soluzione the sims gameboy] [http://getm0ney.freewebpage.org/lib/casse-home/ casse home theatre senza fili] [http://mauballe.125mb.com/web/upskirts/ upskirts] [http://gawelzba.t35.com/library/html/sniper-.htm sniper 2. missione suicida] [http://huruple.125mb.com/text/directory/vasco-rossi/ vasco rossi senza parole] [http://scaleslea.freewebpage.org/text/directory/eos-/ eos 350 d kit ef s 18 55mm canon] [http://mauballe.125mb.com/web/hoss-homeless/ hoss homeless] [http://www.freewebtown.com/boogiejames/topic/bmw-m.htm bmw m5 usata] [http://wainfan.t35.com/view/new/ragazza-lloret.htm ragazza lloret de mar] [http://licohwar.homeblock.com/library/html/jennifer-ma/ jennifer ma revolution] [http://wainfan.t35.com/view/new/appunto-biochimica.htm appunto biochimica] [http://coarmago.t35.com/content/view/naturalismo/ naturalismo] [http://flheddin.125mb.com/content/view/www-segundamano.htm www segundamano] [http://getraylo.freeweb7.com/img/styles/ottica-decoder.htm ottica decoder] [http://getm0ney.freewebpage.org/lib/usb-/ usb 802 11b netgear] [http://mauballe.125mb.com/web/frigoriferi-indesit/ frigoriferi indesit classe a] [http://beshennayabelka.freehostia.com/content/view/la-fate.htm la fate ignoranti] [http://mcwardlo.t35.com/library/html/sill-aria/ sill aria] [http://mcwardlo.t35.com/library/html/epson-epln/ epson epl-n7000] [http://licohwar.homeblock.com/library/html/smne/ s1m0ne] [http://www.freewebtown.com/boogiejames/topic/ranco-lago.htm ranco, lago-] [http://www.freewebtown.com/starbriteyellow/resources/articles/parker-vector.htm parker vector 3] [http://greensticky.freehostia.com/library/html/famosas-famosas/ famosas famosas] [http://greensticky.freehostia.com/library/html/prestito-cuneo/ prestito cuneo] [http://selemku.t35.com/text/directory/poesia-don.htm poesia don baky] [http://oedi.freehostia.com/text/directory/af-/ af 70-300 f 4-5 6 d] [http://www.freewebtown.com/boogiejames/topic/trapezio.htm trapezio] [http://saline-joy.freehostia.com/web/i-promised.htm i promised myself] [http://mcwardlo.t35.com/library/html/qundo-o/ qundo o sol se for mid] [http://failtoexpress.freehostia.com/html/video-u.htm video u2] [http://oedi.freehostia.com/text/directory/epson-stylus/ epson stylus 460] [http://beshennayabelka.freehostia.com/content/view/sex-links.htm sex links] [http://greensticky.freehostia.com/library/html/barbieworld/ barbieworld] [http://lorcaxon.homeblock.com/data/furtiva/ furtiva] [http://gawelzba.t35.com/library/html/canzone-venete.htm canzone venete] [http://zoelverd.freeweb7.com/description/lib/crenoterapia/ crenoterapia] [http://grahrens.125mb.com/view/new/guiness-dei/ guiness dei primati] [http://scaleslea.freewebpage.org/text/directory/the-perfect/ the perfect storm] [http://gawelzba.t35.com/library/html/francesco-dell.htm francesco dell uomo] [http://getm0ney.freewebpage.org/lib/segnali-di/ segnali di caserma] [http://getm0ney.freewebpage.org/lib/deck-yu/ deck yu gi oh] [http://licohwar.homeblock.com/library/html/video-corsa/ video corsa tori pamplona] [http://lorcaxon.homeblock.com/data/goold-mineri/ goold mineri] [http://lorcaxon.homeblock.com/data/inni-calcio/ inni calcio] [http://licohwar.homeblock.com/library/html/philips-lcd/ philips lcd tv 30] [http://saline-joy.freehostia.com/web/donne-della.htm donne della mannoia] [http://saline-joy.freehostia.com/web/karolina-kurkova.htm karolina kurkova nude] [http://mauballe.125mb.com/web/simulatore-pc/ simulatore pc videogiochi] [http://saline-joy.freehostia.com/web/km-mini.htm km0 mini benzina auto km 0] [http://selemku.t35.com/text/directory/icone.htm icone] [http://licohwar.homeblock.com/library/html/hercules-audio/ hercules audio] [http://benevolently.freehostia.com/content/view/donne-vecchie/ donne vecchie arrapate] [http://licohwar.homeblock.com/library/html/quartet/ quartet] [http://selemku.t35.com/text/directory/sbloccare-codici.htm sbloccare codici tre] [http://gawelzba.t35.com/library/html/jamming.htm jamming] [http://mcwardlo.t35.com/library/html/everthing-i/ everthing i do i do it for you] [http://huruple.125mb.com/text/directory/www-bigsausagepizza/ www bigsausagepizza com] [http://getm0ney.freewebpage.org/lib/britax-duo/ britax duo plus] [http://mcwardlo.t35.com/library/html/american-college/ american college] [http://www.freewebtown.com/prncessprncipe/library/html/screensaver-animato.htm screensaver animato] [http://kopapguw.homeblock.com/topic/volo-roma/ volo roma torino] [http://licohwar.homeblock.com/library/html/www-ex/ www ex jugo estrada de] [http://benevolently.freehostia.com/content/view/max-de/ max de angelis l evaso] [http://wainfan.t35.com/view/new/lavatrici-rex.htm lavatrici rex incasso] [http://benevolently.freehostia.com/content/view/cerco-schiavo/ cerco schiavo] [http://boreldar.t35.com/text/directory/vincenzo-bellini.htm vincenzo bellini norma film dvd] [http://www.freewebtown.com/starbriteyellow/resources/articles/sagrantino-montefalco.htm sagrantino montefalco arnaldo caprai] [http://failtoexpress.freehostia.com/html/the-happy.htm the happy ending phantom planet] [http://zoelverd.freeweb7.com/description/lib/midi-alexia/ midi alexia] [http://beshennayabelka.freehostia.com/content/view/palmari-cellulari.htm palmari cellulari con gps] [http://huruple.125mb.com/text/directory/mini-jeux/ mini jeux] [http://selemku.t35.com/text/directory/htt-www.htm htt www libero it] [http://www.freewebtown.com/boogiejames/topic/frigorifero-rt.htm frigorifero rt 57] [http://www.freewebtown.com/starbriteyellow/resources/articles/siti-calcio.htm siti calcio] [http://www.freewebtown.com/boogiejames/topic/submersed.htm submersed] [http://mauballe.125mb.com/web/burroughs-john/ burroughs, john] [http://licohwar.homeblock.com/library/html/tom-end/ tom end jerri] [http://coarmago.t35.com/content/view/chicas-gratis/ chicas gratis] [http://huruple.125mb.com/text/directory/takashi-shimura/ takashi shimura] [http://www.freewebtown.com/boogiejames/topic/gm-accessori.htm gm accessori audio] [http://huruple.125mb.com/text/directory/roma-costa/ roma costa rica] [http://wainfan.t35.com/view/new/eretismo.htm eretismo] [http://mcwardlo.t35.com/library/html/conserviera-industria/ conserviera industria - macchine e attrezzature] [http://licohwar.homeblock.com/library/html/pc-sdram/ pc133 sdram sodimm] [http://scaleslea.freewebpage.org/text/directory/hotel-per/ hotel per scambisti] [http://oedi.freehostia.com/text/directory/extraterrestri/ extraterrestri] [http://saline-joy.freehostia.com/web/www-roadrunner.htm www roadrunner com] [http://coarmago.t35.com/content/view/canciones-de/ canciones de erreway] [http://grahrens.125mb.com/view/new/zoe-zeman/ zoe zeman] [http://grahrens.125mb.com/view/new/ati-radeon/ ati radeon 9600 pro 256 mb agp 8x] [http://oedi.freehostia.com/text/directory/buzzle/ buzzle] [http://mcwardlo.t35.com/library/html/bicchieri-pvc/ bicchieri pvc] [http://www.freewebtown.com/prncessprncipe/library/html/video-tgp.htm video tgp gratis] [http://wainfan.t35.com/view/new/micro-hifi.htm micro hi-fi jvc mp3] [http://www.freewebtown.com/prncessprncipe/library/html/olio-corpo.htm olio corpo biotherm] [http://greensticky.freehostia.com/library/html/lily-cole/ lily cole] [http://benevolently.freehostia.com/content/view/r-hp/ r707 hp] [http://kopapguw.homeblock.com/topic/impensato/ impensato] [http://gawelzba.t35.com/library/html/sigma-mm.htm sigma 18-50mm f3 5-5 6 dc] [http://huruple.125mb.com/text/directory/thief-/ thief 3 - trailer] [http://saline-joy.freehostia.com/web/riabilitazione-neurologica.htm riabilitazione neurologica] [http://coarmago.t35.com/content/view/trans-con/ trans con amico] [http://mauballe.125mb.com/web/monitor-lcd/ monitor lcd 17 samtron] [http://beshennayabelka.freehostia.com/content/view/www-tisali.htm www tisali it] [http://grahrens.125mb.com/view/new/franck-adventure/ franck adventure 3] [http://huruple.125mb.com/text/directory/islander/ islander] [http://mcwardlo.t35.com/library/html/bartok-il/ bartok il magnifico] [http://www.freewebtown.com/prncessprncipe/library/html/www-hotmail.htm www hotmail com pe] [http://www.freewebtown.com/prncessprncipe/library/html/philips-digitale.htm philips digitale terrestre] [http://www.freewebtown.com/boogiejames/topic/www-irid.htm www irid il] [http://flheddin.125mb.com/content/view/assicurazioni-per.htm assicurazioni per viaggi] [http://zoelverd.freeweb7.com/description/lib/auricolare-bluetooth/ auricolare bluetooth per palmari] [http://flheddin.125mb.com/content/view/iraq-video.htm iraq video su web mostra ostaggio usa d] [http://getraylo.freeweb7.com/img/styles/audio-key.htm audio key 256mb] [http://getm0ney.freewebpage.org/lib/film-porno/ film porno italiani gratis] [http://licohwar.homeblock.com/library/html/marea-td/ marea td 100] [http://selemku.t35.com/text/directory/canon-digital.htm canon digital ixus i 5] [http://beshennayabelka.freehostia.com/content/view/video-torture.htm video torture americane] [http://kopapguw.homeblock.com/topic/video-gia/ video gia despina] [http://mcwardlo.t35.com/library/html/la-fontaine/ la fontaine, jean de-] [http://licohwar.homeblock.com/library/html/donne-sessoamatoriale/ donne sessoamatoriale] [http://www.freewebtown.com/prncessprncipe/library/html/transparency-adapter.htm transparency adapter a3 ii] [http://oedi.freehostia.com/text/directory/mp-player/ mp3 player sport] [http://boreldar.t35.com/text/directory/nokia-i.htm nokia 9300i communicator] [http://boreldar.t35.com/text/directory/scarica-gioco.htm scarica gioco computer] [http://www.freewebtown.com/prncessprncipe/library/html/sorsa-kalevi.htm sorsa, kalevi taisto] [http://gawelzba.t35.com/library/html/il-segreto.htm il segreto del bosco vecchio dino] [http://getraylo.freeweb7.com/img/styles/ultimo-cd.htm ultimo cd di giorgia] [http://wainfan.t35.com/view/new/sitio-adulto.htm sitio adulto] [http://oedi.freehostia.com/text/directory/sicilia-province/ sicilia province e comuni] [http://licohwar.homeblock.com/library/html/cruscotto-multipla/ cruscotto multipla] [http://mauballe.125mb.com/web/netsim/ netsim] [http://benevolently.freehostia.com/content/view/la-grande/ la grande caccia] [http://saline-joy.freehostia.com/web/spartito.htm spartito] [http://kopapguw.homeblock.com/topic/centro-ingrosso/ centro ingrosso abbigliamento bologna] [http://failtoexpress.freehostia.com/html/pacific-poker.htm pacific poker com] [http://getm0ney.freewebpage.org/lib/combo-dvd/ combo dvd lg] [http://kopapguw.homeblock.com/topic/orologico/ orologico] [http://lorcaxon.homeblock.com/data/dvd-kiss/ dvd kiss dp] [http://selemku.t35.com/text/directory/digital-mp.htm digital mp3 player 1 gb] [http://www.freewebtown.com/boogiejames/topic/www-italiauno.htm www italiauno it] [http://licohwar.homeblock.com/library/html/zena/ zena] [http://www.freewebtown.com/boogiejames/topic/un-weekend.htm un week-end da leoni] [http://coarmago.t35.com/content/view/webcam-italia/ webcam italia] [http://coarmago.t35.com/content/view/dvd-elisa/ dvd elisa di rivombrosa] [http://zoelverd.freeweb7.com/description/lib/jeans-diesel/ jeans diesel 30] [http://www.freewebtown.com/starbriteyellow/resources/articles/palmare-mappe.htm palmare mappe] [http://kopapguw.homeblock.com/topic/liquori-italia/ liquori italia toscana] [http://getm0ney.freewebpage.org/lib/hamlet-hexdu/ hamlet hexd5u2] [http://saline-joy.freehostia.com/web/scientist.htm scientist] [http://www.freewebtown.com/boogiejames/topic/kodak-easyshare.htm kodak easyshare printer dock plus] [http://scaleslea.freewebpage.org/text/directory/reclutamento-truppa/ reclutamento truppa 6 concorso 3 bando] [http://greensticky.freehostia.com/library/html/lamezia-genova/ lamezia- genova volo aereo] [http://benevolently.freehostia.com/content/view/massaggiatrici-roma/ massaggiatrici roma] [http://grahrens.125mb.com/view/new/pioneer-dvas/ pioneer dv-585a-s] [http://beshennayabelka.freehostia.com/content/view/cazzo-di.htm cazzo di colore] [http://mcwardlo.t35.com/library/html/tagawa/ tagawa] [http://grahrens.125mb.com/view/new/leutschau/ leutschau] [http://mcwardlo.t35.com/library/html/hub-per/ hub per rete usb] {{task}}
This task is about [[numeric arrays]]. For '''hashes''' or '''associative arrays''', please see [[Creating an Associative Array]].
This task is about [[numeric arrays]]. For '''hashes''' or '''associative arrays''', please see [[Creating an Associative Array]].



Revision as of 14:14, 12 August 2007

Task
Creating an Array
You are encouraged to solve this task according to the task description, using any language you may know.

This task is about numeric arrays. For hashes or associative arrays, please see Creating an Associative Array.

In this task, the goal is to create an array. Mention if the array base begins at a number other than zero.

ActionScript

//  ActionScript arrays are zero-based
// 
//  creates an empty array
var arr1:Array = new Array();
//  creates an array with 3 numerical values
var arr2:Array = new Array(1,2,3);
// 
// or just use the shorthand
var u:Array = [];
var v:Array = [1,2,3];

Ada

Compiler: GCC 4.1.2

Ada array indices may begin at any value, not just 0 or 1

type Arr is array (Integer range <>) of Integer;
Uninitialized : Arr (1 .. 10);
Initialized_1 : Arr (1 .. 20) := (others => 1);
Initialized_2 : Arr := (1 .. 30 => 2);
Const         : constant Arr := (1 .. 10 => 1, 11 .. 20 => 2, 21 | 22 => 3);
Centered      : Arr (-50..50) := (0 => 1, Others => 0);

Ada arrays may be indexed by enumerated types, which are discrete non-numeric types

type Days is (Mon, Tue, Wed, Thu, Fri, Sat, Sun);
type Activities is (Work, Fish);
type Daily_Activities is array(Days) of Activities;
This_Week : Daily_Activities := (Mon..Fri => Work, Others => Fish);

AppleScript

AppleScript supports "arrays" as "lists," and they are not limited by a single type.

set array1 to {}
set array2 to {1, 2, 3, 4, "hello", "world"}

BASIC

Interpeter: QuickBasic 4.5, PB 7.1

REM Force index to start at 1..n
OPTION BASE 1
REM Force index to start at 0..n
OPTION BASE 0
REM Specify that the array is dynamic and not static
'$DYNAMIC
DIM SHARED myArray(-10 TO 10, 10 TO 30) AS STRING
REDIM SHARED myArray(20, 20) AS STRING
myArray(1,1) = "Item1"
myArray(1,2) = "Item2"

C

Compiler: GCC, MSVC, BCC, Watcom

Libraries: Standard Dynamic

#include <stdlib.h> /* for malloc */
#include <string.h> /* for memset */
int n = 10 * sizeof(int);
int *myArray = (int*)malloc(n);
if(myArray != NULL)
{
  memset(myArray, 0, n);
  myArray[0] = 1;
  myArray[1] = 2;
  free(myArray);
  myArray = NULL;
}

Static

 int myArray2[10] = { 1, 2, 0}; /* 3..9 := 0 */

C

Compiler: GCC, Visual C , BCC, Watcom


Using dynamically-allocated memory:

 const int n = 10;
 int* myArray = new int[n];
 if(myArray != NULL)
 {
   myArray[0] = 1;
   myArray[1] = 2;
   delete[] myArray;
   myArray = NULL;
 }

Using fixed memory:

 int myArray2[10] = { 1, 2, 0}; /* 3..9 := 0 */

Libraries: STL

 // STL
 std::vector<int> myArray3(10);
 myArray3.push_back(1);
 myArray3.push_back(2);

Libraries: Qt

 // Qt
 QVector<int> myArray4(10);
 myArray4.push_back(1);
 myArray4.push_back(2);

Libraries: Microsoft Foundation Classes

 // MFC
 CArray<int,int> myArray5(10);
 myArray5.Add(1);
 myArray5.Add(2);

C#

Example of array of 10 int types:

 int[] numbers = new int[10];

Example of array of 3 string types:

 string[] words = { "these", "are", "arrays" };

You can also declare the size of the array and initialize the values at the same time:

 int[] more_numbers = new int[3]{ 21, 14 ,63 };


For Multi-Deminsional arrays you declare them the same except for a comma in the type declaration.

The following creates a 3x2 int matrix

 int[,] number_matrix = new int[3,2];

As with the previous examples you can also initialize the values of the array, the only difference being each row in the matrix must be enclosed in its own braces.

 string[,] string_matrix = { {"I","swam"}, {"in","the"}, {"freezing","water"} };

or

 string[,] funny_matrix = new string[2,2]{ {"clowns", "are"} , {"not", "funny"} };

Clean

Array denotations are overloaded in Clean, therefore we explicitly specify the types. There are lazy, strict, and unboxed array.

Lazy array

Create a lazy array of strings using an array denotation.

array :: {String}
array = {"Hello", "World"}

Create a lazy array of floating point values by sharing a single element.

array :: {Real}
array = createArray 10 3.1415

Create a lazy array of integers using an array (and also a list) comprehension.

array :: {Int}
array = {x \\ x <- [1 .. 10]}

Strict array

Create a strict array of integers.

array :: {!Int}
array = {x \\ x <- [1 .. 10]}

Unboxed array

Create an unboxed array of characters, also known as String.

array :: {#Char}
array = {x \\ x <- ['a' .. 'z']}

ColdFusion

Creates a one-dimensional Array

<cfset arr1 = ArrayNew(1)>

Creates a two-dimensional Array in CFScript

<cfscript>
  arr2 = ArrayNew(2);
</cfscript>

ColdFusion Arrays are NOT zero-based, they begin at index 1

Common Lisp

Creates a one-dimensional array of length 10.

(make-array 10)

Creates a two-dimensional array with dimensions 10x20.

(make-array '(10 20))

make-array may be called with a number of optional arguments.

(make-array 4 :element-type 'fixnum :initial-contents '(1 2 3 4) :adjustable t)

D

Compiler: DMD,GDC

// dynamic array
int[] numbers = new int[5];

// static array
int[5] = [0,1,2,3,4];

Forth

Forth has a variety of ways to allocate arrays of data, though it has no built-in array handling words, favoring pointer manipulation.

Static array of 200 cells, uninitialized:

create MyArray 200 cells allot
here MyArray - cell / constant MyArraySize

Static array containing the numbers 1 to 5

create MyArray   1 , 2 , 3 , 4 , 5 ,
here MyArray - cell / constant MyArraySize

Dynamic array allocation:

0 value MyArray
200 cells allocate to MyArray

Dynamic array free:

MyArray free
0 to MyArray

Fortran

Default case:

      integer a(10)

this will have ten elements. Counting starts at 1. If a zero-based array is needed, declare like this:

      integer a(0:9)

this mechanism can be extended to any numerical indices, and allowed number of dimensions (and of course to other data types than integers). For example

      real*8 (25:29,12)

will be an two-dimensional, 5x12-array of 8-byte floats, where the first dimension can be addressed numerically as 25, 26, 27, 28 or 29 (and the second dimension as 1 .. 12).


IDL

IDL doesn't really distinguish between scalars and arrays - the same operations that can create the one can usually create the other as well.

 a = 3
 help,a
 A               INT       =        3
 print,a^2
      9
 a = [3,5,8,7]
 help,a
 A               INT       = Array[4]
 print,a^2
      9      25      64      49

Java

For example for an array of 10 int values:

 int[] intArray = new int[10];

Creating an array of Strings:

 String[] s = {"hello" , "World" };

JavaScript

 var myArray = new Array();
 var myArray2 = new Array("Item1","Item2");
 var myArray3 = ["Item1", "Item2"];

MAXScript

Interpreter: 3D Studio Max 8

 myArray = #()
 myArray2 = #("Item1", "Item2")

mIRC Scripting Language

Interpeter: mIRC Script Editor Libraries: mArray Snippet

alias creatmearray { .echo -a $array_create(MyArray, 5, 10) }

OCaml

Using an array literal:

 let array = [| 1; 2; 3; 4; 5 |];;

To create an array of five elements with the value 0:

 let num_items = 5 and initial_value = 0;;
 let array = Array.make num_items initial_value

To create an array with contents defined by passing each index to a callback (in this example, the array is set to the squares of the numbers 0 through 4):

 let callback index = index * index;;
 let array = Array.init 5 callback


Perl

Interpreter: Perl 5

my @empty;
my @empty_too = ();
my @populated   = ('This', 'That', 'And', 'The', 'Other');
print $populated[2];
# And

my $aref = ['This', 'That', 'And', 'The', 'Other'];
print aref->[2];
# And
# having to quote like that really sucks, and that's why we got syntactic sugar
my @wakey_wakey = qw(coffee sugar cream);

push @wakey_wakey, 'spoon';
# add spoon to right-hand side
my $cutlery = pop @wakey_wakey;
# remove spoon

unshift @wakey_wakey, 'cup';
# add cup to left-hand side
my $container = shift @wakey_wakey;
# remove cup
my @multi_dimensional = (
    [0, 1, 2, 3],
    [qw(a b c d e f g)],
    [qw(! $ %

Toka

Toka allows creation of an array using is-array. Access to the elements is done using get-element, put-element, get-char-element, and put-char-element functions. You can not initialize the values automatically using the core array functions.

 100 cells is-array foo
 100 chars is-array bar