从下面的一段话中进行这样的操作:
1.进行字符串的截取,满足这样的条件(每个单词中只能含有“a”或“A”不能有“E”或者“e”),把所有满足这个条件的单词输出在控制台上;
2.把截取出来的字符串按字数的升序排序;
3.字符串如下:Douyu built-in Java language compiler based on OpenJDK Javac Compiler (b60 version),And had revised and expanded, with the Http server can be integrated in the controller layer, after a strong power play,You just modify the Java source file, and then refresh your browser will be able to view the results,At the same time the compiler is also a cornerstone of automation to achieve ORM我截取字符串可以实现,但是下面我就不会了,请哪位高手替我解决一下!谢谢!
1.进行字符串的截取,满足这样的条件(每个单词中只能含有“a”或“A”不能有“E”或者“e”),把所有满足这个条件的单词输出在控制台上;
2.把截取出来的字符串按字数的升序排序;
3.字符串如下:Douyu built-in Java language compiler based on OpenJDK Javac Compiler (b60 version),And had revised and expanded, with the Http server can be integrated in the controller layer, after a strong power play,You just modify the Java source file, and then refresh your browser will be able to view the results,At the same time the compiler is also a cornerstone of automation to achieve ORM我截取字符串可以实现,但是下面我就不会了,请哪位高手替我解决一下!谢谢!
解决方案 »
- 如何进行判断,使加入数据库的内容不重复
- 访问WebService时出现异常,请帮我看看这个异常信息是什么意思?
- 兄弟们,俺要找工作了,想找几份java软件题做做,谢谢!
- java将中文转换为MAX,后如何在转回中文。下面有将中文转换为MAX方法,谢谢。。。。
- 一个老土的问题
- struts中的与中文的转换码列表那里有?
- 运行applet出现的问题。。。java.security.AccessControlException: access denied
- spring的缓存注解的问题
- springboot集成websocket
- 基于Druid连接池的JdbcTemplate.queryForObject 一直返回空对象
- 这样的页面的表单该怎么提交
- 哪里有关于JSTL中文版的书?
貌似是效率最低的办法
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;public class Test { public static void main(String[] args) {
String str = "Douyu built-in Java language compiler based on OpenJDK Javac Compiler (b60 version),And had revised and expanded, with the Http server can be integrated in the controller layer, after a strong power play,You just modify the Java source file, and then refresh your browser will be able to view the results,At the same time the compiler is also a cornerstone of automation to achieve ORM";
List<String> words = new ArrayList<String>(Arrays.asList(str.split("[\\p{Space}\\(\\),]+")));
for (int i = 0; i < words.size(); i++) {
String word = words.get(i);
if (word.contains("e") || word.contains("E")) {
words.remove(word);
}
}
System.out.println("控制台打印:");
for (String word : words) {
System.out.println(word);
}
//排序
Collections.sort(words, new Comparator<String>() {
@Override
public int compare(String str1, String str2) {
return str1.length()-str2.length();
}
});
System.out.println("\n控制台打印:");
for (String word : words) {
System.out.println(word);
}
}
}
能用数组尽量用数组撒(跟集合不是一个数量级的,O(∩_∩)O哈哈~)
String 下面自带方法的..
package com.wang.UI;import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;public class Test implements Comparable<Test> {
private int i;
private String s;
public Test(String s, int i){
this.s =s;
this.i =i;
}
public static void main(String[] args) {
List<Test> l =new ArrayList<Test>();
Pattern p = Pattern.compile("[\\w&&[^EeaA]]*[aA]+[\\w&&[^Ee]]*\\b");
Matcher m =p.matcher(
"Douyu built-in Java language compiler based on OpenJDK Javac Compiler (b60 version),And had revised and expanded, with the Http server can be integrated in the controller layer, after a strong power play,You just modify the Java source file, and then refresh your browser will be able to view the results,At the same time the compiler is also a cornerstone of automation to achieve ORM");
while(m.find()){
String s =m.group();
System.out.println(s);
//装入List
l.add(new Test(s,s.length()));
}
//排序
int n =l.size();
Test temp;
for(int i = 0;i<n;i++){
for(int j =i+1;j<n;j++)
if(l.get(i).compareTo(l.get(j))>0){
temp =l.get(i);
l.set(i, l.get(j));
l.set(j, temp);
}
}
for(int i = 0;i<n;i++){
System.out.println("-----------------");
System.out.println(l.get(i).getS());
}
} public int getI() {
return i;
}
public void setI(int i) {
this.i = i;
}
public String getS() {
return s;
}
public void setS(String s) {
this.s = s;
}
public int compareTo(Test t) {
//学习inkfish的
/*if(this.i<t.getI()){
return -1;
}else if (this.i ==t.getI()){
return 0;
}else{
return 1;
}*/
return this.i-t.getI();
}
}inkfish 的值得学习了!