我想从字符串中截断子字符串,最多60个字符,但也希望在子字符串中获得完整的单词.这是我正在尝试的.
String originalText =" Bangladesh's first day of Test cricket on Indian soil has not been a good one. They end the day having conceded 71 runs in the last 10 overs, which meant they are already staring at a total of 356. M Vijay was solid and languid as he made his ninth Test century and third of the season. ";
String afterOptimized=originalText.substring(0, 60);
System.out.println("This is text . "+afterOptimized);
Run Code Online (Sandbox Code Playgroud)
这是输出
This is text . Bangladesh's first day of Test …Run Code Online (Sandbox Code Playgroud) 我enum在java中使用,这是枚举
public enum AbuseSectionType{
MUSIC("Music"), DANCE("Dance"), SOLO("Solo"), ACT("Act")
private String displayString;
AbuseSectionType(String displayValue) {
this.displayString = displayValue;
}
@JsonValue
public String getDisplayString() {
return displayString;
}
public void setDisplayString(String displayString) {
this.displayString = displayString;
}
}
Run Code Online (Sandbox Code Playgroud)
我正在努力获取价值AbuseSectionType.valueOf("Music")。我没有得到任何枚举常量,也没有发现错误。我应该有价值MUSIC。