Removing text after `:`, `:` included I need to remove last text after : in my String and : too. I have tried this. Please review. If there is a better way to do, please tell me.

String test = "temp:content:region:deposit:up";
System.out.println(test.replace(test.substring(test.lastIndexOf(":"), test.length()), ""));
Using regexp (replace) isn't the best solution. I think you should use only substring:

System.out.println(test.substring(0, test.lastIndexOf(":")))