“找不到标志”?

时间:2011-05-02 12:51:13

标签: java string-utils

我真的要去这里了。我试图扭转字符串中的单词。我正在尝试使用StringUtils并完成导入。为什么我会得到“无法找到符号。方法......”?

这是我的代码:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package mkrsassignment10;

import com.sun.xml.internal.ws.util.StringUtils;


/**
 *
 * @author mso_
 */
public class Main {
/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    //Q1
    //int index;
    String sentence = "is this a sentence or is it not ";

    // 1a
    String[] myStringArray = sentence.split(" "); //Split the sentence by space.
    String wordLongest = myStringArray[0]; //assign longest word to the first word
    for (int i=0; i < sentence.length(); ++i) { //loop through the sentence to find the longest word
      if(wordLongest.length() < myStringArray.length)
        wordLongest = myStringArray[i];
      else
    break;
    }
    System.out.println("The word is: " + "'"+ wordLongest +"'" + " and it is " + wordLongest.length() + " characters long");

    // 1b
    //for (int i = 0; i < myStringArray.length; i++) {
    //    myStringArray.toString();
    //    else
    //    break;

    // 1c
    String reversed = StringUtils.reverseDelimited(sentence, " "); // <--- here is the error
    System.out.println("Reversed words:" + reversed);

    // 1d
    sentence = new StringBuffer(sentence).reverse().toString();
    System.out.println("Reversed String : " + sentence);
  }



}

1 个答案:

答案 0 :(得分:2)

我想你使用Apache Commons Lang。它希望第二个参数的char不是String。 试试这个:StringUtils.reverseDelimited(sentence, ' ');