用java编写程序,String strings []={" string "," starting "," strong "," street "," stir "," studeng "," so
时间: 2024-05-01 07:15:37 浏览: 60
java里的string
使用Java编写程序可以通过创建一个类来实现。下面是一个示例程序,它将给定的字符串数组按照字母顺序进行排序:
```java
import java.util.Arrays;
public class StringArraySort {
public static void main(String[] args) {
String[] strings = {"string", "starting", "strong", "street", "stir", "student", "so"};
// 使用Arrays.sort()方法对字符串数组进行排序
Arrays.sort(strings);
// 打印排序后的结果
for (String str : strings) {
System.out.println(str);
}
}
}
```
运行以上程序,输出结果为:
```
so
starting
stir
string
street
strong
student
```
阅读全文