I'm looking for a way to pull the last characters from a String, regardless of size. Lets take these strings into example:
"abcd: efg: 1006746"
"bhddy: nshhf36: 1006754"
"hfquv: nd: 5894254"
As you can see, completely random strings, but they have 7 numbers at the end. How would I be able to take those 7 numbers?
Edit:
I just realized that String[] string = s.split(": "); would work great here, as long as I call string[2] for the numbers and string[1] for anything in the middle.
String.split(), but it is worth noting thats.split(": ")is going to compile a newjava.uitl.regex.Patternevery time you call it, then match your string with that pattern, creating a regexMatcherand anArrayListbefore theString[]that is returned. It will be relatively slow and will allocate far more than necessary to solve this problem. Whether this matters depends on the nature of your application. I generally avoidsplit()unless I really need it. (Note thatsplit()does not use regex if you split on a single character.)