public class Strings extends Object
Constructor and Description |
---|
Strings() |
Modifier and Type | Method and Description |
---|---|
static boolean |
canParse(Class type)
Whether the given type is parsable via
parse(java.lang.String, java.lang.Class) . |
static String |
getClassName(Class cls)
Return only the class name, without package.
|
static String |
getClassName(String fullName)
Return only the class name.
|
static String |
getPackageName(Class cls)
Return only the package, or empty string if none.
|
static String |
getPackageName(String fullName)
Return only the package, or empty string if none.
|
static String |
join(Object[] strings,
String token)
Joins the given strings, placing the given token between them.
|
static Object |
parse(String val,
Class type)
Return
val as the type specified by
type . |
static String |
replace(String str,
String from,
String to)
Replace all instances of
from in str
with to . |
static String[] |
split(String str,
String token,
int max)
Splits the given string on the given token.
|
static Class |
toClass(String str,
boolean resolve,
ClassLoader loader)
Return the class for the given string, correctly handling
primitive types.
|
static Class |
toClass(String str,
ClassLoader loader)
Return the class for the given string, correctly handling
primitive types.
|
public static String replace(String str, String from, String to)
from
in str
with to
.str
- the candidate string to replacefrom
- the token to replaceto
- the new tokenpublic static String[] split(String str, String token, int max)
String.split(String,int)
method, but does
not treat the given token as a regular expression.public static String join(Object[] strings, String token)
public static Class toClass(String str, ClassLoader loader)
RuntimeException
- on load errorpublic static Class toClass(String str, boolean resolve, ClassLoader loader)
RuntimeException
- on load errorpublic static String getClassName(Class cls)
public static String getPackageName(Class cls)
public static String getPackageName(String fullName)
public static Object parse(String val, Class type)
val
as the type specified by
type
. If type
is a primitive, the
primitive wrapper type is created and returned, and
null
s are converted to the Java default for the
primitive type.val
- The string value to parsetype
- The type to parse. This must be a primitive or a
primitive wrapper, or one of BigDecimal
,
BigInteger
, String
, Date
.IllegalArgumentException
- if type
is not a
supported type, or if val
cannot be
converted into an instance of type type
.public static boolean canParse(Class type)
parse(java.lang.String, java.lang.Class)
.Copyright © 2002–2019. All rights reserved.