I have a string like "~~banana~apple~". I want to split that string with "~" is seperator and i want last element in the array after split is "" not "apple".
String fruits = "~~banana~apple~";
String[] arr = fruits.split("~");
String last = ""; //Last string i need
if (arr.length > 0 )
last = arr[arr.length-1];
System.out.println("last: " + last);
//The result
last: apple
//but i want in this case the value of last must be "" because afer "apple" have "~".
Sorry my bad english.
fruitsvariable and you are splittingtenvariable. Is that a typo or partial code.~so there's nothing to point to as the last element.