function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
NAMALA VENUGOPALNAMALA VENUGOPAL 

how to call array functions into apex class?

Best Answer chosen by NAMALA VENUGOPAL
JyothsnaJyothsna (Salesforce Developers) 
Hi Venugopal,

Arrays in Apex are basically the same as Lists in Apex. There is no logical distinction between the Arrays and Lists as their internal data structure and methods are also same but the array syntax is little traditional like Java.

Syntax:
<String> [] arrayOfProducts = new List<String>();

Please check the below links for better understand of Arrays and List.
http://sfdcsrini.blogspot.com/2014/04/what-is-collections-and-what-are.html  (http://sfdcsrini.blogspot.com/2014/04/what-is-collections-and-what-are.html )

http://blog.jeffdouglas.com/2011/01/06/fun-with-salesforce-collections/

Hope this helps you!
Best Regards,
​Jytohsna

All Answers

Abhishek Vishwakarma 5Abhishek Vishwakarma 5
Hi Namala,

Please follow this link : https://developer.salesforce.com/docs/atlas.en-us.apex_workbook.meta/apex_workbook/apex4_3.htm

Hope this resolves your Issue.

Thanks,
Abhishek
DebasisDebasis
Hi Namala,
There really aren't arrays in Apex, but you can use the array notation to declare lists.Arrays in Apex are basically the same as Lists in Apex. There is no logical distinction between the Arrays and Lists as their internal data structure and methods are also same but the array syntax is little traditional like Java.
There are few limitation we have in array and for that salesforce having list and set and map collection, limittaion are as below
1.We can not store different class objects into the same array, reason is that array can store a single data type.
2.We can add an element to the end of the array.But inserting and deleting  an element to the middle of the array is difficult.
3.We can retrieve the elements from the array but there is no such methods to process the elements.
Syntax:
<String> [] arrayOfProducts = new List<String>();
Example:
Suppose, we would like to store name of our Products, then we could use the Array in which we could store the Product Names as shown below. You could access the particular Product by specifying the index.
//Defining array
String [] arrayOfProducts = new List<String>();
//Adding elements in Array
arrayOfProducts.add('HCL');
arrayOfProducts.add('H2SO4');
arrayOfProducts.add('NACL');
arrayOfProducts.add('H2O');
arrayOfProducts.add('N2');
arrayOfProducts.add('U296');

for (Integer i = 0; i<arrayOfProducts.size(); i++) {
    //This loop will print all the elements in array
    system.debug('Values In Array: '+arrayOfProducts[i]);   
}
accessing array element by using index:
You could access any element in array by using the index as shown below:
//Accessing the element in array
//We would access the element at Index 3
System.debug('Value at Index 3 is :'+arrayOfProducts[3]);

You can also refer more on thisl ink:
https://developer.salesforce.com/docs/atlas.en-us.apex_workbook.meta/apex_workbook/apex4_3.htm

Thanks,
Debasis
Mahesh DMahesh D
Hi Namala,

Arrays and Lists
Apex has a list collection type that holds an ordered collection of objects. List elements can be accessed with an index or can be sorted if they’re primitive types, such as Integers or Strings. You’ll typically use a list whenever you want to store a set of values that can be accessed with an index. As you’ll see in later tutorials, lists are also used to hold the results of queries.

You can access an element of a list using a zero-based index, or by iterating over the list.  Here's how to create a new list, and display its size:
 
List<Integer> myList = new List<Integer>();
System.debug(myList.size());

Arrays in Apex are synonymous with lists—Apex provides an array-like syntax for accessing lists. Here is an alternative way to create exactly the same list:
 
Integer[] myList = new List<Integer>();

You can also define a list variable and initialize it at the same time as shown in the following example, which displays the string 'two':
 
List<String> myStrings = new List<String> { 'one', 'two' };

To add a new element to a list, use the add method.
 
myList.add(101);

You can use the array notation to get or modify an existing value.

Also check the below code:
Integer[] myList = new List<Integer>();
//Adds a new element with value 10 to the end of the list
myList.add(10);  

// Retrieve the first element of the list
// using array notation
Integer i = myList[0];  
// or using the get method
Integer j = myList.get(0);
System.debug('First element in the array using myList[0] is ' + i);
System.debug('First element in the array using myList.get(0) is ' + j);

Also go through the below URL for more information:

https://developer.salesforce.com/docs/atlas.en-us.apex_workbook.meta/apex_workbook/apex4_3.htm

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_list.htm

http://salesforce.stackexchange.com/questions/55941/simple-apex-class-to-return-a-list-of-strings


Please do let me know if it helps you.

Regards,
Mahesh
JyothsnaJyothsna (Salesforce Developers) 
Hi Venugopal,

Arrays in Apex are basically the same as Lists in Apex. There is no logical distinction between the Arrays and Lists as their internal data structure and methods are also same but the array syntax is little traditional like Java.

Syntax:
<String> [] arrayOfProducts = new List<String>();

Please check the below links for better understand of Arrays and List.
http://sfdcsrini.blogspot.com/2014/04/what-is-collections-and-what-are.html  (http://sfdcsrini.blogspot.com/2014/04/what-is-collections-and-what-are.html )

http://blog.jeffdouglas.com/2011/01/06/fun-with-salesforce-collections/

Hope this helps you!
Best Regards,
​Jytohsna
This was selected as the best answer