Q:

Remove characters after a certain string java

I'm new in java I have a problem.  I have a string "x.y.z.k", and I want to create a new string "x.y.z." ( so I want to remove all characters just after the last ".").  I will appreciate it if somebody will help me.  

A:

String test = "x.y.z.k";
int lastPos = test.lastIndexOf('.'); 
String extractedString = test.substring(0, lastPos);

Outputs:
x.y.z
This code has been tested at compileonline.com

