-2

I have a string in following format

String s= abc=1,cde=2,efg=3

I only want to extract efg.
I tried by Spilting it but not getting 3 in last part for part[3] it is showing arrays out of bounds exception. I want to extract as I need to increment last part by 1 every time.

Ivar
  • 6,138
  • 12
  • 49
  • 61

1 Answers1

0

If split() results in an array of three elements, the index of the last one is 2 not 3. That could explain the exception. In an array indexes start at 0.

Ralf Renz
  • 1,061
  • 5
  • 7
  • How to do it with given string.. I want only last value of every string in this case it is 3 – user8643408 Nov 14 '17 at 09:38
  • Subtract 1 from the length of the array to obtain the index of the last element: `String lastElement = yourArray[yourArray.length - 1];` – Ole V.V. Nov 14 '17 at 09:53