Get the last three chars from any string - Java

前端 未结 11 1499
情话喂你
情话喂你 2020-12-24 10:21

I\'m trying to take the last three chracters of any string and save it as another String variable. I\'m having some tough time with my thought process.

Strin         


        
11条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-24 10:56

    Alternative way for "insufficient string length or null" save:

    String numbers = defaultValue();
    try{
       numbers = word.substring(word.length() - 3);
    } catch(Exception e) {
       System.out.println("Insufficient String length");
    }
    

提交回复
热议问题