Как проверить, содержит ли строка символ пробела, пробел или символ "". Если возможно, приведите пример Java.
Например: String = "test word";
String = "test word";
String str = "Test Word"; if(str.indexOf(' ') != -1){ return true; } else{ return false; }
Используйте org.apache.commons.lang.StringUtils.
логическое значение withWhiteSpace = StringUtils.contains ("мое имя", "");
StringUtils.deleteWhitespace (null) = null StringUtils.deleteWhitespace ("") = "" StringUtils.deleteWhitespace ("abc") = "abc "StringUtils.deleteWhitespace (" ab c ") =" abc "
import java.util.Scanner; public class camelCase { public static void main(String[] args) { Scanner user_input=new Scanner(System.in); String Line1; Line1 = user_input.nextLine(); int j=1; //Now Read each word from the Line and convert it to Camel Case String result = "", result1 = ""; for (int i = 0; i < Line1.length(); i++) { String next = Line1.substring(i, i + 1); System.out.println(next + " i Value:" + i + " j Value:" + j); if (i == 0 | j == 1 ) { result += next.toUpperCase(); } else { result += next.toLowerCase(); } if (Character.isWhitespace(Line1.charAt(i)) == true) { j=1; } else { j=0; } } System.out.println(result);
package com.test; public class Test { public static void main(String[] args) { String str = "TestCode "; if (str.indexOf(" ") > -1) { System.out.println("Yes"); } else { System.out.println("Noo"); } } }