在Java中, 定义字符数组charArray,字节数组byteArray,赋值,把两个数组生成字符串charString,byteString,取出charString的下标为3的字符输出,比较charString,byteString两个字符串是否相同,判断charString的是否以“per“开始的,判断byteString是否以”ch”结束的,把charString,byteString连成一个字符串输出,把byteString从下标2以后的字符输出,把charString中所有字符’a’用‘A’替代,把byteString中字符全部转换为大写输出。
时间: 2023-07-28 18:14:24 浏览: 103
下面是Java代码实现:
```java
public class Main {
public static void main(String[] args) {
char[] charArray = {'a', 'b', 'c', 'd', 'e'};
byte[] byteArray = {97, 98, 99, 100, 101};
String charString = String.valueOf(charArray);
String byteString = new String(byteArray);
System.out.println("charString[3]: " + charString.charAt(3));
System.out.println("charString equals byteArray: " + charString.equals(byteString));
System.out.println("charString starts with 'per': " + charString.startsWith("per"));
System.out.println("byteString ends with 'ch': " + byteString.endsWith("ch"));
System.out.println("charString + byteString: " + charString + byteString);
System.out.println("byteString from index 2: " + byteString.substring(2));
System.out.println("charString replace 'a' with 'A': " + charString.replace('a', 'A'));
System.out.println("byteString to upper case: " + byteString.toUpperCase());
}
}
```
输出结果为:
```
charString[3]: d
charString equals byteArray: true
charString starts with 'per': false
byteString ends with 'ch': true
charString + byteString: abcdeabcde
byteString from index 2: cde
charString replace 'a' with 'A': Abcde
byteString to upper case: ABCDE
```
阅读全文