Question: 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.

Answer: 
You can use String method `.lastIndexOf()` to get the last position of `.` and then use String method `substring()` to extract only the first part of the String, up to the `.` character.
```
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](http://compileonline.com)