fork download
  1. // Create a list and add elements to it in one step
  2. List<String> colors = new List<String> { 'red', 'green', 'blue' };
  3. // Add elements to a list after it has been created
  4. List<String> moreColors = new List<String>();
  5. colors.add('orange');
  6. moreColors.add('purple');
  7. // Get elements from a list
  8. String color1 = moreColors.get(0);
  9. String color2 = moreColors[0];
  10. System.assertEquals(color1, color2);
  11. // Iterate over a list to read elements
  12. System.debug('Print out the colors in moreColors:');
  13. for(String color : moreColors) {
  14. // Write value to the debug log
  15. System.debug(color);
  16. }
  17.  
  18.  
  19.  
  20.  
Success #stdin #stdout #stderr 0.01s 7856KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
./prog:1: expected expression