package com.example.helloworld; /** * Created by carl on 10/21/15. */ public class StringChecker { public static void main(String[] arguments) { String str = "Would you like an apple pie with that?"; System.out.println("This string is: " + str); System.out.println("Length of string is: " + str.length()); System.out.println("The character at position 6:" + str.charAt(6)); System.out.println("The substring from 26 to 28:" + str.substring(26, 28)); System.out.println("The index of first a:" + str.indexOf('a')); System.out.println("The index of the beginning of the :" + "substring "with" " + str.indexOf("with")); System.out.println("The substring in uppercase:" + str.toUpperCase()); } }
运行结果如下:
This string is: Would you like an apple pie with that?
Length of string is: 38
The character at position 6:y
The substring from 26 to 28:e
The index of first a:15
The index of the beginning of the :substring "with" 28
The substring in uppercase:WOULD YOU LIKE AN APPLE PIE WITH THAT?