<%@ page import="java.util.Arrays" pageEncoding="utf-8" %><!doctype html> <html> <head> <meta charset="utf-8"> <title>String Test</title> <style> body { font-size: 14px; } </style> </head>
<body> <% String str1 = "hello"; String str2 = new String("Java 面向对象"); char str[] = {'h', 'e', 'l', 'l', 'o'}; String list[] = new String[] {"hello", "Java", "!"}; int arr[] = {49, 67, 17, 45, 63, 29, 48}; Arrays.sort(arr);
char strarr[] = new char[20]; int n = str2.length(); str2.getChars(0, n, strarr, 0); strarr[6] = 0; // \0不能结束Java字符串
strarr[0] = Character.toLowerCase(strarr[0]); strarr[1] = Character.toUpperCase(strarr[1]);
list = new String[] {"VC", "Visual Studio", "AS", "Java", "Hello"}; String temp; n = list.length; for (int i = 0; i < n - 1; i++) { for (int j = 0; j < n - i - 1; j++) { if (list[j].compareTo(list[j + 1]) > 0) { temp = list[j]; list[j] = list[j + 1]; list[j + 1] = temp; } } } String str3 = list[0].concat(list[1]); String str4 = str3.substring(1, 3); // len = 3 - 1 = 2 String str5 = str3.replace('l', 'L'); String str6 = "This is a key and that isn't an island.".replace("is", "<b>IS</b>");
StringBuffer sb = new StringBuffer("JEEhas is good."); sb.insert(1, '2'); // 在sb[1]的前面插入 sb.delete(4, 7); sb.append(".."); %><table border="1" cellpadding="4" style="border-collapse:collapse"> <tbody> <tr> <td><%= str1 + '(' + str1.length() + ')' %></td> <td><%= str2 + '(' + str2.length() + ')' %></td> <td><%= str %></td> <td><%= strarr %></td> <td><%= Character.isUpperCase(strarr[0]) %></td> </tr> <tr> <td><%= list[0] %></td> <td><%= list[1] %></td> <td><%= list[2] %></td> <td><%= list[3] %></td> <td><%= list[4] %></td> </tr> <tr> <td><%= str3 %></td> <td><%= str4 %></td> <td><%= str5 %></td> <td><%= str6 %></td> <td><%= "Java_Learning".substring(4, 9) %></td> </tr> <tr> <td><%= list[4].indexOf('a') %></td> <td><%= list[4].indexOf("as") %></td> <td><%= list[4].indexOf("sual") %></td> <td><%= list[4].lastIndexOf("dia") %></td> <td><%= list[4].lastIndexOf("dio") %></td> </tr> <tr> <td><%= sb %></td> <td colspan="4" align="center"><%= Arrays.toString(arr) %></td> </tr> </tbody> </table> </body> </html>
|