本文整理了Java中java.lang.Character.valueOf()
方法的一些代码示例,展示了Character.valueOf()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Character.valueOf()
方法的具体详情如下:
包路径:java.lang.Character
类名称:Character
方法名:valueOf
[英]Returns a Character instance for the char value passed.
If it is not necessary to get a new Character instance, it is recommended to use this method instead of the constructor, since it maintains a cache of instances which may result in better performance.
[中]返回传递的字符值的字符实例。
如果不需要获取新的Character实例,建议使用此方法而不是构造函数,因为它会维护实例缓存,从而提高性能。
代码示例来源:origin: apache/incubator-dubbo
public static Character boxed(char v) {
return Character.valueOf(v);
}
代码示例来源:origin: apache/incubator-dubbo
public static Character boxed(char v) {
return Character.valueOf(v);
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Override
public Character getRight() {
return Character.valueOf(rhs);
}
});
代码示例来源:origin: redisson/redisson
/**
* Converts to object array.
*/
public static Character[] valuesOf(char[] array) {
Character[] dest = new Character[array.length];
for (int i = 0; i < array.length; i++) {
dest[i] = Character.valueOf(array[i]);
}
return dest;
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Override
public Character getLeft() {
return Character.valueOf(lhs);
}
代码示例来源:origin: junit-team/junit4
/**
* Asserts that two chars are equal. If they are not
* an AssertionFailedError is thrown with the given message.
*/
static public void assertEquals(String message, char expected, char actual) {
assertEquals(message, Character.valueOf(expected), Character.valueOf(actual));
}
代码示例来源:origin: org.testng/testng
/**
* Asserts that two chars are equal. If they are not,
* an AssertionFailedError, with the given message, is thrown.
* @param actual the actual value
* @param expected the expected value
* @param message the assertion error message
*/
public static void assertEquals(char actual, char expected, String message) {
assertEquals(Character.valueOf(actual), Character.valueOf(expected), message);
}
代码示例来源:origin: clojure/clojure
public Object first(){
return Character.valueOf(s.charAt(i));
}
代码示例来源:origin: org.testng/testng
/**
* Asserts that two chars are equal. If they are not
* an AssertionFailedError is thrown with the given message.
*/
static public void assertEquals(String message, char expected, char actual) {
assertEquals(message, Character.valueOf(expected), Character.valueOf(actual));
}
代码示例来源:origin: spring-projects/spring-framework
private void setAsUnicode(String text) {
int code = Integer.parseInt(text.substring(UNICODE_PREFIX.length()), 16);
setValue(Character.valueOf((char) code));
}
代码示例来源:origin: alibaba/fastjson
public abstract class BeforeFilter implements SerializeFilter {
private static final ThreadLocal<JSONSerializer> serializerLocal = new ThreadLocal<JSONSerializer>();
private static final ThreadLocal<Character> seperatorLocal = new ThreadLocal<Character>();
private final static Character COMMA = Character.valueOf(',');
final char writeBefore(JSONSerializer serializer, Object object, char seperator) {
serializerLocal.set(serializer);
seperatorLocal.set(seperator);
writeBefore(object);
serializerLocal.set(null);
return seperatorLocal.get();
}
protected final void writeKeyValue(String key, Object value) {
JSONSerializer serializer = serializerLocal.get();
char seperator = seperatorLocal.get();
serializer.writeKeyValue(seperator, key, value);
if (seperator != ',') {
seperatorLocal.set(COMMA);
}
}
public abstract void writeBefore(Object object);
}
代码示例来源:origin: redisson/redisson
@Override
public Object instantiate(Class objectClass, FSTObjectInput in, FSTClazzInfo serializationInfo, FSTClazzInfo.FSTFieldInfo referencee, int streamPosition) throws Exception {
Object res = Character.valueOf(in.readChar());
return res;
}
代码示例来源:origin: apache/incubator-dubbo
/**
* Creates a map of the classes fields.
*/
protected static Object getParamArg(Class cl) {
if (!cl.isPrimitive())
return null;
else if (boolean.class.equals(cl))
return Boolean.FALSE;
else if (byte.class.equals(cl))
return Byte.valueOf((byte) 0);
else if (short.class.equals(cl))
return Short.valueOf((short) 0);
else if (char.class.equals(cl))
return Character.valueOf((char) 0);
else if (int.class.equals(cl))
return Integer.valueOf(0);
else if (long.class.equals(cl))
return Long.valueOf(0);
else if (float.class.equals(cl))
return Double.valueOf(0);
else if (double.class.equals(cl))
return Double.valueOf(0);
else
throw new UnsupportedOperationException();
}
代码示例来源:origin: org.apache.commons/commons-lang3
/**
* Return the next character in the iteration
*
* @return {@code Character} for the next character
*/
@Override
public Character next() {
if (!hasNext) {
throw new NoSuchElementException();
}
final char cur = current;
prepareNext();
return Character.valueOf(cur);
}
代码示例来源:origin: google/guava
/**
* Returns the default value of {@code type} as defined by JLS --- {@code 0} for numbers, {@code
* false} for {@code boolean} and {@code '\0'} for {@code char}. For non-primitive types and
* {@code void}, {@code null} is returned.
*/
@SuppressWarnings("unchecked")
public static <T> @Nullable T defaultValue(Class<T> type) {
checkNotNull(type);
if (type == boolean.class) {
return (T) Boolean.FALSE;
} else if (type == char.class) {
return (T) Character.valueOf('\0');
} else if (type == byte.class) {
return (T) Byte.valueOf((byte) 0);
} else if (type == short.class) {
return (T) Short.valueOf((short) 0);
} else if (type == int.class) {
return (T) Integer.valueOf(0);
} else if (type == long.class) {
return (T) Long.valueOf(0L);
} else if (type == float.class) {
return (T) FLOAT_DEFAULT;
} else if (type == double.class) {
return (T) DOUBLE_DEFAULT;
} else {
return null;
}
}
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public void setAsText(@Nullable String text) throws IllegalArgumentException {
if (this.allowEmpty && !StringUtils.hasLength(text)) {
// Treat empty String as null value.
setValue(null);
}
else if (text == null) {
throw new IllegalArgumentException("null String cannot be converted to char type");
}
else if (isUnicodeCharacterSequence(text)) {
setAsUnicode(text);
}
else if (text.length() == 1) {
setValue(Character.valueOf(text.charAt(0)));
}
else {
throw new IllegalArgumentException("String [" + text + "] with length " +
text.length() + " cannot be converted to char type: neither Unicode nor single character");
}
}
代码示例来源:origin: google/guava
public void testCompare() {
for (char x : VALUES) {
for (char y : VALUES) {
// note: spec requires only that the sign is the same
assertEquals(x + ", " + y, Character.valueOf(x).compareTo(y), Chars.compare(x, y));
}
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testNumberToCharacter() {
assertEquals(Character.valueOf('A'), conversionService.convert(65, Character.class));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testStringToCharacter() {
assertEquals(Character.valueOf('1'), conversionService.convert("1", Character.class));
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testChar() {
final TypeTestClass class1 = new TypeTestClass();
final TypeTestClass class2 = new TypeTestClass();
class2.charField = 'z';
final DiffResult list = class1.diff(class2);
assertEquals(1, list.getNumberOfDiffs());
final Diff<?> diff = list.getDiffs().get(0);
assertEquals(Character.valueOf(class1.charField), diff.getLeft());
assertEquals(Character.valueOf(class2.charField), diff.getRight());
}
内容来源于网络,如有侵权,请联系作者删除!