本文整理了Java中java.lang.Character.<init>()
方法的一些代码示例,展示了Character.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Character.<init>()
方法的具体详情如下:
包路径:java.lang.Character
类名称:Character
方法名:<init>
[英]Constructs a new Character with the specified primitive char value.
[中]
代码示例来源:origin: log4j/log4j
/**
* Returns a Character instance representing the specified char.
* Character.valueOf was added in JDK 1.5.
*
* @param c a character value.
* @return a Character instance representing c.
*/
protected static Character valueOf(final char c) {
return new Character(c);
}
代码示例来源:origin: google/j2objc
/**
* 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, new Character(expected), new Character(actual));
}
代码示例来源:origin: stackoverflow.com
1. String stringValueOf = String.valueOf('c'); // most efficient
2. String stringValueOfCharArray = String.valueOf(new char[]{x});
3. String characterToString = Character.toString('c');
4. String characterObjectToString = new Character('c').toString();
// Although this method seems very simple,
// this is less efficient because the concatenation
// expands to new StringBuilder().append(x).append("").toString();
5. String concatBlankString = 'c' + "";
6. String fromCharArray = new String(new char[]{x});
代码示例来源:origin: apache/incubator-dubbo
public static Object getConstructorArg(Class<?> cl) {
if (boolean.class.equals(cl) || Boolean.class.equals(cl)) {
return Boolean.FALSE;
} else if (byte.class.equals(cl) || Byte.class.equals(cl)) {
return Byte.valueOf((byte) 0);
} else if (short.class.equals(cl) || Short.class.equals(cl)) {
return Short.valueOf((short) 0);
} else if (int.class.equals(cl) || Integer.class.equals(cl)) {
return Integer.valueOf(0);
} else if (long.class.equals(cl) || Long.class.equals(cl)) {
return Long.valueOf(0L);
} else if (float.class.equals(cl) || Float.class.equals(cl)) {
return Float.valueOf((float) 0);
} else if (double.class.equals(cl) || Double.class.equals(cl)) {
return Double.valueOf((double) 0);
} else if (char.class.equals(cl) || Character.class.equals(cl)) {
return new Character((char) 0);
} else {
return null;
}
}
代码示例来源:origin: apache/incubator-dubbo
public static Object getConstructorArg(Class<?> cl) {
if (boolean.class.equals(cl) || Boolean.class.equals(cl)) {
return Boolean.FALSE;
} else if (byte.class.equals(cl) || Byte.class.equals(cl)) {
return Byte.valueOf((byte) 0);
} else if (short.class.equals(cl) || Short.class.equals(cl)) {
return Short.valueOf((short) 0);
} else if (int.class.equals(cl) || Integer.class.equals(cl)) {
return Integer.valueOf(0);
} else if (long.class.equals(cl) || Long.class.equals(cl)) {
return Long.valueOf(0L);
} else if (float.class.equals(cl) || Float.class.equals(cl)) {
return Float.valueOf((float) 0);
} else if (double.class.equals(cl) || Double.class.equals(cl)) {
return Double.valueOf((double) 0);
} else if (char.class.equals(cl) || Character.class.equals(cl)) {
return new Character((char) 0);
} else {
return null;
}
}
代码示例来源: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 new Byte((byte) 0);
else if (short.class.equals(cl))
return new Short((short) 0);
else if (char.class.equals(cl))
return new Character((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 Float.valueOf(0);
else if (double.class.equals(cl))
return Double.valueOf(0);
else
throw new UnsupportedOperationException();
}
代码示例来源:origin: commons-lang/commons-lang
/**
* Return the next character in the iteration
*
* @return <code>Character</code> for the next character
*/
public Object next() {
if (hasNext == false) {
throw new NoSuchElementException();
}
char cur = current;
prepareNext();
return new Character(cur);
}
代码示例来源:origin: redisson/redisson
Object getValue(ClassLoader cl, ClassPool cp, Method m) {
return new Character(getValue());
}
代码示例来源:origin: google/guava
@Generates
private Character generateCharacter() {
return new Character(generateChar());
}
代码示例来源:origin: apache/flink
@Override
protected Character[] getTestData() {
Random rnd = new Random(874597969123412341L);
int rndInt = rnd.nextInt((int) Character.MAX_VALUE);
return new Character[] {new Character('a'), new Character('@'), new Character('ä'),
new Character('1'), new Character((char) rndInt),
Character.MAX_VALUE, Character.MIN_VALUE};
}
}
代码示例来源:origin: google/guava
static void checkExactMatches(CharMatcher m, char[] chars) {
Set<Character> positive = Sets.newHashSetWithExpectedSize(chars.length);
for (char c : chars) {
positive.add(c);
}
for (int c = 0; c <= Character.MAX_VALUE; c++) {
assertFalse(positive.contains(new Character((char) c)) ^ m.matches((char) c));
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void skipImmutableCharacter() {
doSkipImmutableValue(new Character('x'));
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testToObject_char() {
final char[] b = null;
assertArrayEquals(null, ArrayUtils.toObject(b));
assertSame(ArrayUtils.EMPTY_CHARACTER_OBJECT_ARRAY,
ArrayUtils.toObject(new char[0]));
assertTrue(Arrays.equals(
new Character[]{new Character(Character.MIN_VALUE),
new Character(Character.MAX_VALUE), new Character('0')},
ArrayUtils.toObject(new char[]{Character.MIN_VALUE, Character.MAX_VALUE,
'0'}))
);
}
代码示例来源:origin: org.apache.commons/commons-lang3
/**
* Test wrapper for char primitive.
*/
@Test
public void testReflectionCharacter() {
final Character c = new Character('A');
assertEquals(this.toBaseString(c) + "[value=A]", ToStringBuilder.reflectionToString(c));
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testUnescapeHexCharsHtml() {
// Simple easy to grok test
assertEquals("hex number unescape", "\u0080\u009F", StringEscapeUtils.unescapeHtml4("€Ÿ"));
assertEquals("hex number unescape", "\u0080\u009F", StringEscapeUtils.unescapeHtml4("€Ÿ"));
// Test all Character values:
for (char i = Character.MIN_VALUE; i < Character.MAX_VALUE; i++) {
final Character c1 = new Character(i);
final Character c2 = new Character((char)(i+1));
final String expected = c1.toString() + c2.toString();
final String escapedC1 = "&#x" + Integer.toHexString((c1.charValue())) + ";";
final String escapedC2 = "&#x" + Integer.toHexString((c2.charValue())) + ";";
assertEquals("hex number unescape index " + (int)i, expected, StringEscapeUtils.unescapeHtml4(escapedC1 + escapedC2));
}
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testToIntValue_Character_int() {
assertEquals(0, CharUtils.toIntValue(new Character('0'), -1));
assertEquals(3, CharUtils.toIntValue(new Character('3'), -1));
assertEquals(-1, CharUtils.toIntValue(new Character('A'), -1));
assertEquals(-1, CharUtils.toIntValue(null, -1));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testCharacterEditorWithAllowEmpty() {
CharBean cb = new CharBean();
BeanWrapper bw = new BeanWrapperImpl(cb);
bw.registerCustomEditor(Character.class, new CharacterEditor(true));
bw.setPropertyValue("myCharacter", new Character('c'));
assertEquals(new Character('c'), cb.getMyCharacter());
bw.setPropertyValue("myCharacter", "c");
assertEquals(new Character('c'), cb.getMyCharacter());
bw.setPropertyValue("myCharacter", "\u0041");
assertEquals(new Character('A'), cb.getMyCharacter());
bw.setPropertyValue("myCharacter", " ");
assertEquals(new Character(' '), cb.getMyCharacter());
bw.setPropertyValue("myCharacter", "");
assertNull(cb.getMyCharacter());
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testToIntValue_Character() {
assertEquals(0, CharUtils.toIntValue(new Character('0')));
assertEquals(3, CharUtils.toIntValue(new Character('3')));
try {
CharUtils.toIntValue(null);
fail("An IllegalArgumentException should have been thrown");
} catch (final IllegalArgumentException ex) {}
try {
CharUtils.toIntValue(CHARACTER_A);
fail("An IllegalArgumentException should have been thrown");
} catch (final IllegalArgumentException ex) {}
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testToCharacterObject_String() {
assertNull(CharUtils.toCharacterObject(null));
assertNull(CharUtils.toCharacterObject(""));
assertEquals(new Character('a'), CharUtils.toCharacterObject("a"));
assertEquals(new Character('a'), CharUtils.toCharacterObject("abc"));
assertSame(CharUtils.toCharacterObject("a"), CharUtils.toCharacterObject("a"));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testCharacterEditor() {
CharBean cb = new CharBean();
BeanWrapper bw = new BeanWrapperImpl(cb);
bw.setPropertyValue("myChar", new Character('c'));
assertEquals('c', cb.getMyChar());
bw.setPropertyValue("myChar", "c");
assertEquals('c', cb.getMyChar());
bw.setPropertyValue("myChar", "\u0041");
assertEquals('A', cb.getMyChar());
bw.setPropertyValue("myChar", "\\u0022");
assertEquals('"', cb.getMyChar());
CharacterEditor editor = new CharacterEditor(false);
editor.setAsText("M");
assertEquals("M", editor.getAsText());
}
内容来源于网络,如有侵权,请联系作者删除!