⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 accessstring.java

📁 java的书上例子
💻 JAVA
字号:
//例7.2 String类的对象的访问
class accessString {
		public static void main(String argvs[]){
			String s = "This program will show you how to use the class String!";
			System.out.println("from string  \""+s+"\"");
			System.out.println("You can :\n1. get the length :"+s.length());
			System.out.println("2. know the char at the specified index 6 is :"+s.charAt(6));
			System.out.println("3. index a character or a substring in several ways as");
			System.out.println("	the first occurrence of  'a'is :"+s.indexOf('a'));
			System.out .println("	the first occurrence of  'a' from index 15 is :"+s.indexOf('a',15));
			System.out.println("	the first occurrence of  'ow'is :"+s.indexOf("ow"));
			System.out .println("	the first occurrence of  'ow' from index 15 is :"+s.indexOf("ow",25));
			System.out.println("	the last occurrence of  'a'is :"+s.lastIndexOf('a'));
			System.out .println("	the last occurrence of  'a' from index 15 is :"+s.lastIndexOf('a',15));
			char sub[] = new char[10];
			byte sub2[] = new byte[10];
			System.out.print("4.	get chars into an array from index 5 to 12:");
			s.getChars(5,12,sub,0);
		    System.out.println(sub);
			System.out.print("5.	get the ascii code of 'a':");
			System.out.println(sub2[5]);
		}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -