Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

arraylist add at index

/* add(index, item to add); */
ArrayList<String> languages = new ArrayList<String>(); 
languages.add("PHP");
languages.add("JAVA");
languages.add("C#");
languages.add(2, "RUBY"); /* at index 2, add RUBY*/
ArrayList<int> numbers = new ArrayList<int>(); 
numbers.add(9);
numbers.add(14);
numbers.add(2);
numbers.add(1, 15); /* at index 1, add 15*/
/*
  After Execution:
  languages => PHP JAVA RUBY C#
  numbers => 9 15 14 2
*/
 
PREVIOUS NEXT
Tagged: #arraylist #add #index
ADD COMMENT
Topic
Name
2+9 =