要提取最后 n 个字符,只需使用 charAt() 方法打印 (length-n) 第个字符到第 n 个字符。示例在线演示public class ExtractingCharactersFromStrings { public static void main(String args[]) { String str = "Hi welcome to tutorialspoint"; int n = 5; int initial = str.length()-5; for(int i=initial; i
toString()方法以字符串格式返回当前对象。示例实时演示public class Test { public static void main(String args[]) { Test obj = new Test(); System.out.println(obj.toString()); System.out.println("Hello"); } }输出Test@2a139a55 Hello