在Apex数组是基本相同的Apex列表。有作为其内部数据结构中的数组和列表之间没有逻辑的区别和方法也相同,但数组的语法是传统的小像Java。
下面是产品的Array的表示:
指数0 - HCL
指数1 - H2SO4
索引2 - NACL
指数3 - H2O
指数4 - N2
指数5 - U296
句法:
- <String> [] = arrayOfProducts The new List <String> ();
例:
假设,我们想存储我们的产品名称,然后我们可以使用中,我们可以存储的产品名称如下图所示的阵列。可以通过指定索引访问特定产品。
- // Define an array
- String [] = arrayOfProducts The new List <String> ();
- // The added array element
- ArrayOfProducts.add ('HCL');
- ArrayOfProducts.add ('H2SO4');
- ArrayOfProducts.add ('NACL');
- ArrayOfProducts.add ('water');
- ArrayOfProducts.add ("N2");
- ArrayOfProducts.add ('U296');
- For the (integer i = 0; I <arrayOfProducts.size (); my ++) {
- // This loop prints all the elements of the array
- System.debug (array of values: '+ arrayOfProducts [I]);
- }}
通过使用索引访问数组元素:
你可以通过使用索引来访问任何元素的数组,如下所示:
- // Access the elements in the array
- // We will access the element at index 3
- System.debug ('in exponent 3 has the value:' + arrayOfProducts [3]);
转载本站内容时,请务必注明来自W3xue,违者必究。