I want to know how to get desired output using split alone.
You can't. If the input ends with a single (not double) ampersand, either you split on it or you don't.
If you split on it, there'll be a trailing empty String.
If you don't, the last element of the split will contain the ampersand.
st=st.substring(0,st.lastIndexOf("&"));
What does that do if the input doesn't end with an ampersand at all? e.g. for the input
"12&45&&56&7"
edit Matthew beat me by 7 seconds!