比较字符串、字符串前后缀、查找字符串、提取字符串、字符串转换
import java.awt.*; import java.applet.*; public class StringDemo extends Applet{ String str1="student"; String str2=new String("china"); char a[]={'t','e','a','c','h','e','r'}; String str3=new String(a); String str4=new String(a,2,4); byte b[]={97,98,99,100,101}; String str5=new String(b,0); public void init(){} public void paint(Graphics g){ g.drawString("str1="+str1, 20, 20); g.drawString("str2="+str2, 20, 40); g.drawString("str3="+str3, 20, 60); g.drawString("str4="+str4, 20, 80); g.drawString("str5="+str5, 20, 100); g.drawString("str1的长度"+str1.length(), 20, 120); g.drawString("str2的第二个字符为:"+str2.charAt(1), 20, 140); g.drawString("str2转化成为大写:"+str2.toUpperCase(), 20, 160); g.drawString(""ch"在str3中的位置为:"+str3.indexOf("ch"), 20, 180); g.drawString("str4的前缀与"ac"比较的结果为:"+str4.startsWith("ac"), 20, 200); g.drawString("str5的第二个位置开始长度为2的子串为:"+str5.substring(1,3), 20, 220); } }