从下面的一段话中进行这样的操作:
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.   

    先截出来,放到一个list里面。然后list不是有排序么。排下就好了
    貌似是效率最低的办法
      

  2.   

    随便写了一下,没有考虑效率问题:import java.util.ArrayList;
    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);
    }
    }
    }
      

  3.   

    这个应该可以先以空格作分隔符放入一个list再去迭代判断是否含有需要的字母吧
      

  4.   

      将List改为char[]型数组就好了
       能用数组尽量用数组撒(跟集合不是一个数量级的,O(∩_∩)O哈哈~)
       String 下面自带方法的..
      

  5.   


    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 的值得学习了!