String
Text. These methods work as in Java 11.
Final classJavaJava 11 docs
public final class String implements Serializable, Comparable<String>, CharSequenceCompare text with equals(…), never with ==. Join text with +, or build longer text with StringBuilder or String.format.
Example
NpcEx npc = NpcAPI.search().nearest();
if (npc != null && npc.getName() != null && npc.getName().startsWith("Goblin")) {
// ...
}Members
Methods
- charcharAt(int)
The character at a position.
- booleancontains(CharSequence)
Whether this text contains other text.
- booleanendsWith(String)
Whether this text ends with other text.
- booleanequals(Object)
Whether two texts are the same.
- booleanequalsIgnoreCase(String)
Whether two texts are the same, ignoring capital letters.
- intindexOf(String)
Where other text first appears.
- booleanisBlank()
Whether the text is empty or only spaces.
- booleanisEmpty()
Whether the text has no characters.
- intlength()
The number of characters.
- booleanstartsWith(String)
Whether this text starts with other text.
charAt(int)
public char charAt(int index)The character at a position.
Parameters
index- The position, counting from
0.
Returns
The character.
contains(CharSequence)
public boolean contains(CharSequence s)Whether this text contains other text.
Parameters
s- The text to look for.
Returns
true if it does. Capital letters must match.
endsWith(String)
public boolean endsWith(String suffix)Whether this text ends with other text.
Parameters
suffix- The ending to check.
Returns
true if it does.
equals(Object)
public boolean equals(Object anObject)Whether two texts are the same.
Parameters
anObject- The text to compare with.
Returns
true if they match exactly, including capital letters.
equalsIgnoreCase(String)
public boolean equalsIgnoreCase(String anotherString)Whether two texts are the same, ignoring capital letters.
Parameters
anotherString- The text to compare with.
Returns
true if they match.
indexOf(String)
public int indexOf(String str)Where other text first appears.
Parameters
str- The text to look for.
Returns
The position, counting from 0, or -1 when it is not found.
isBlank()
public boolean isBlank()Whether the text is empty or only spaces.
Returns
true if it is.
isEmpty()
public boolean isEmpty()Whether the text has no characters.
Returns
true if its length is 0.
length()
public int length()The number of characters.
Returns
The length.
startsWith(String)
public boolean startsWith(String prefix)Whether this text starts with other text.
Parameters
prefix- The start to check.
Returns
true if it does.
Also allowed
These work as in the Java 11 docs.
CASE_INSENSITIVE_ORDER, chars, codePointAt, codePointBefore, codePointCount, codePoints, compare, compareTo, compareToIgnoreCase, concat, contentEquals, copyValueOf, format, getBytes, getChars, hashCode, indexOf, intern, join, lastIndexOf, lines, matches, new String, offsetByCodePoints, regionMatches, repeat, replace, replaceAll, replaceFirst, split, startsWith, strip, stripLeading, stripTrailing, subSequence, substring, toCharArray, toLowerCase, toString, toUpperCase, trim, valueOf