Yes, it's possible, you can use a block anywhere you can use an individual statement. Variables declared within that block will only be valid within the block. E.g.:
void method() {
String allThisCodeCanSeeMe;
// ...
{
String onlyThisBlockCanSeeMe;
// ...
}
{
String onlyThisSecondBlockCanSeeMe;
// ...
}
// ....
}
But: Usually, if you find yourself wanting to do something like this, it suggests that you need to break the code into smaller functions/methods, and have what's currently your one method call those smaller parts:
void method() {
String thisMethodCanSeeMe;
// ...
this.aSmallerMethod(); // <== Can pass in `thisMethodCanSeeMe`
this.anotherSmallerMethod(); // <== if needed
// ...
}
private void aSmallerMethod() {
String onlyThisMethodCanSeeMe;
// ...
}
private void anotherSmallerMethod() {
String onlyThisSecondSmallerMethodCanSeeMe;
// ...
}