Answered by : grieving-grebe-7pud8y2ox3rq
arrayName[arrayName.length() - 1];
Source : | Last Update : Thu, 12 Mar 20
Answered by : stupid-seal-lkprxu0vos8u
firstNum = numbers[0];
lastNum = numbers[numbers.length-1];
Source : https://stackoverflow.com/questions/39860739/how-to-get-first-and-last-element-in-an-array-in-java | Last Update : Fri, 15 May 20
Answered by : sobhanbera
int[] arr = new int[5]; //length of the array is 5
int val = arr[arr.length - 1]; //here variable val stores the last element of arr
Source : | Last Update : Fri, 14 Aug 20
Answered by : crazy-constrictor-tw3nhlaule7k
int last = list.get(list.size() - 1);
Source : | Last Update : Wed, 23 Sep 20
Answered by : tender-teira-dw5o0fsiikce
firstNum = numbers.get(0);
lastNum = numbers.get(numbers.size() - 1);
Source : https://stackoverflow.com/questions/39860739/how-to-get-first-and-last-element-in-an-array-in-java/39860831 | Last Update : Sat, 05 Sep 20
Answered by : kritik-modi
int a[]={1,2,3};
int last = a[a.length-1];
Source : | Last Update : Sat, 27 Aug 22
Answered by : outstanding-okapi-ka4n9df41foa
// Array of doubles
double[] array_doubles = {2.5, 6.2, 8.2, 4846.354, 9.6};
// First position
double firstNum = array_doubles[0]; // 2.5
// Last position
double lastNum = array_doubles[array_doubles.length - 1]; // 9.6
Source : https://stackoverflow.com/questions/39860739/how-to-get-first-and-last-element-in-an-array-in-java | Last Update : Fri, 14 Jan 22