public class Strings extends Object
| Modifier and Type | Method and Description |
|---|---|
static String |
concat(Object... strings)
Concatenates multiple values into a string.
|
static boolean |
contains(String whole,
String sub)
Determines whether a string contains a given substring.
|
static double |
desigToDec(String designation)
Attempts to determine the ICRS Declination from
an IAU-style designation such as "
2MASS J04355524+1630331"
following the specifications in the document
https://cdsweb.u-strasbg.fr/Dic/iau-spec.html. |
static double[] |
desigToIcrs(String designation)
Attempts to decode
an IAU-style designation such as "
2MASS J04355524+1630331"
to determine its sky position,
following the specifications in the document
https://cdsweb.u-strasbg.fr/Dic/iau-spec.html. |
static double |
desigToRa(String designation)
Attempts to determine the ICRS Right Ascension from
an IAU-style designation such as "
2MASS J04355524+1630331"
following the specifications in the document
https://cdsweb.u-strasbg.fr/Dic/iau-spec.html. |
static boolean |
endsWith(String whole,
String end)
Determines whether a string ends with a certain substring.
|
static boolean |
equals(String s1,
String s2)
Determines whether two strings are equal.
|
static boolean |
equalsIgnoreCase(String s1,
String s2)
Determines whether two strings are equal apart from possible
upper/lower case distinctions.
|
static String |
join(String separator,
Object... words)
Joins multiple values into a string, with a given
separator between each pair.
|
static int |
length(String str)
Returns the length of a string in characters.
|
static boolean |
matches(String str,
String regex)
Tests whether a string matches a given regular expression.
|
static String |
matchGroup(String str,
String regex)
Returns the first grouped expression matched in a string defined
by a regular expression.
|
static String |
padWithZeros(long value,
int ndigit)
Takes an integer argument and returns a string representing the
same numeric value but padded with leading zeros to a specified
length.
|
static String |
replaceAll(String str,
String regex,
String replacement)
Replaces all occurrences of a regular expression in a string with
a different substring value.
|
static String |
replaceFirst(String str,
String regex,
String replacement)
Replaces the first occurrence of a regular expression in a string with
a different substring value.
|
static String[] |
split(String words)
Splits a string into an array of space-separated words.
|
static String[] |
split(String words,
String regex)
Splits a string into an array of words separated by a given
regular expression.
|
static boolean |
startsWith(String whole,
String start)
Determines whether a string starts with a certain substring.
|
static String |
substring(String str,
int startIndex)
Returns the last part of a given string.
|
static String |
substring(String str,
int startIndex,
int endIndex)
Returns a substring of a given string.
|
static String |
toLowerCase(String str)
Returns an lowercased version of a string.
|
static String |
toUpperCase(String str)
Returns an uppercased version of a string.
|
static String |
trim(String str)
Trims whitespace from both ends of a string.
|
public static String concat(Object... strings)
s1+s2+..., but this method makes sure that
values are converted to strings, with the blank value invisible.strings - one or more stringspublic static String join(String separator, Object... words)
separator - string to insert between adjacent wordswords - one or more values to joinseparatorpublic static boolean equals(String s1, String s2)
s1==s2,
which can (for technical reasons) return false even if the
strings are the same.s1 - first strings2 - second stringpublic static boolean equalsIgnoreCase(String s1, String s2)
s1 - first strings2 - second stringpublic static boolean startsWith(String whole, String start)
whole - the string to teststart - the sequence that may appear at the start of
wholewhole are
the same as startpublic static boolean endsWith(String whole, String end)
whole - the string to testend - the sequence that may appear at the end of
wholewhole are
the same as endpublic static boolean contains(String whole, String sub)
whole - the string to testsub - the sequence that may appear within wholesub appears within
wholepublic static int length(String str)
str - stringstrpublic static String[] split(String words)
The result is an array of strings, and if you want to use the
individual elements you need to use square-bracket indexing,
with [0] representing the first object
words - string with embedded spaces delimiting the wordspublic static String[] split(String words, String regex)
The result is an array of strings, and if you want to use the
individual elements you need to use square-bracket indexing,
with [0] representing the first object
words - string with multiple partsregex - regular expression delimiting the different words in
the words parameterpublic static boolean matches(String str, String regex)
str - string to testregex - regular expression stringregex matches str anywherepublic static String matchGroup(String str, String regex)
str - string to match againstregex - regular expression containing a grouped sectionregex didn't match str)public static String replaceFirst(String str, String regex, String replacement)
str - string to manipulateregex - regular expression to match in strreplacement - replacement stringstr, but with the first match (if any) of
regex replaced by replacementpublic static String replaceAll(String str, String regex, String replacement)
str - string to manipulateregex - regular expression to match in strreplacement - replacement stringstr, but with all matches of
regex replaced by replacementpublic static String substring(String str, int startIndex)
str - the input stringstartIndex - the beginning index, inclusivestr, omitting the first
startIndex characterspublic static String substring(String str, int startIndex, int endIndex)
startIndex
and continues to the character at index endIndex-1
Thus the length of the substring is endIndex-startIndex.str - the input stringstartIndex - the beginning index, inclusiveendIndex - the end index, inclusivestrpublic static String toUpperCase(String str)
str - input stringstrpublic static String toLowerCase(String str)
str - input stringstrpublic static String trim(String str)
str - input stringpublic static String padWithZeros(long value, int ndigit)
value - numeric value to padndigit - the number of digits in the resulting stringvalue with
at least ndigit characterspublic static double desigToRa(String designation)
2MASS J04355524+1630331"
following the specifications in the document
https://cdsweb.u-strasbg.fr/Dic/iau-spec.html.
Note: this function should be used with considerable care. Such designators are intended for object identification and not for communicating sky positions, so that the resulting positions are likely to lack precision, and may be inaccurate. If positional information is available from other sources, it should almost certainly be used instead. But if there's no other choice, this may be used as a fallback.
Note also
that a designator with no coordsystem-specific flag character
(a leading "J", "B" or "G")
is considered to be B1950, not J2000.
designation - designation string in IAU formatpublic static double desigToDec(String designation)
2MASS J04355524+1630331"
following the specifications in the document
https://cdsweb.u-strasbg.fr/Dic/iau-spec.html.
Note: this function should be used with considerable care. Such designators are intended for object identification and not for communicating sky positions, so that the resulting positions are likely to lack precision, and may be inaccurate. If positional information is available from other sources, it should almost certainly be used instead. But if there's no other choice, this may be used as a fallback.
Note also
that a designator with no coordsystem-specific flag character
(a leading "J", "B" or "G")
is considered to be B1950, not J2000.
designation - designation string in IAU formatpublic static double[] desigToIcrs(String designation)
2MASS J04355524+1630331"
to determine its sky position,
following the specifications in the document
https://cdsweb.u-strasbg.fr/Dic/iau-spec.html.
Obviously, this only works where the sequence part of the designation takes one of the family of coordinate-based forms.
Note: this function should be used with considerable care. Such designators are intended for object identification and not for communicating sky positions, so that the resulting positions are likely to lack precision, and may be inaccurate. If positional information is available from other sources, it should almost certainly be used instead. But if there's no other choice, this may be used as a fallback.
Note also
that a designator with no coordsystem-specific flag character
(a leading "J", "B" or "G")
is considered to be B1950, not J2000.
designation - designation string in IAU formatnull if no position can be decodedCopyright © 2025 Central Laboratory of the Research Councils. All Rights Reserved.