Chars是基本char類型的實(shí)用工具類。
以下是com.google.common.primitives.Chars類的聲明:
@GwtCompatible(emulated=true) public final class Chars extends Object
S.N. | 字段及說明 |
---|---|
1 |
static int BYTES 所需要的字節(jié)數(shù)來表示一個(gè)原始char值。 |
S.N. | 方法及說明 |
---|---|
1 |
static List<Character> asList(char... backingArray) 返回由指定數(shù)組支持的固定大小的列表,類似 Arrays.asList(Object[]). |
2 |
static char checkedCast(long value) 返回char值等于value值,如果可能的話。 |
3 |
static int compare(char a, char b) 比較兩個(gè)指定的char值。 |
4 |
static char[] concat(char[]... arrays) 每個(gè)數(shù)組提供組合成一個(gè)單一的數(shù)組,則返回值。 |
5 |
static boolean contains(char[] array, char target) 返回true,如果target是否存在在任何地方數(shù)組元素。 |
6 |
static char[] ensureCapacity(char[] array, int minLength, int padding) 返回一個(gè)包含相同的值數(shù)組的數(shù)組,但保證是一個(gè)規(guī)定的最小長(zhǎng)度。 |
7 |
static char fromByteArray(byte[] bytes) 返回char值,其大端表示被存儲(chǔ)在第一個(gè)2字節(jié)的字節(jié);相當(dāng)于 ByteBuffer.wrap(bytes).getChar(). |
8 |
static char fromBytes(byte b1, byte b2) 返回char值的字節(jié)表示是給定2個(gè)字節(jié),在big-endian的順序;相當(dāng)于 Chars.fromByteArray(new byte[] {b1, b2}). |
9 |
static int hashCode(char value) 返回哈希碼的值;等于調(diào)用的結(jié)果 ((Character) value).hashCode(). |
10 |
static int indexOf(char[] array, char target) 返回目標(biāo)數(shù)組的首次出現(xiàn)的索引值。 |
11 |
static int indexOf(char[] array, char[] target) 返回指定目標(biāo)的第一個(gè)匹配的起始位置數(shù)組內(nèi),或-1,如果不存在。 |
12 |
static String join(String separator, char... array) 返回包含由分離器分離所提供的char值字符串。 |
13 |
static int lastIndexOf(char[] array, char target) 返回target 在數(shù)組中最后一個(gè)出現(xiàn)的索引值。 |
14 |
static Comparator<char[]> lexicographicalComparator() 返回一個(gè)比較器,它比較兩個(gè)字符數(shù)組字典順序。 |
15 |
static char max(char... array) 返回在數(shù)組中的最大值。 |
16 |
static char min(char... array) 返回出現(xiàn)在數(shù)組最小值。 |
17 |
static char saturatedCast(long value) 返回值char最近的值。 |
18 |
static char[] toArray(Collection<Character> collection) 復(fù)制字符實(shí)例的集合到原始char值的新數(shù)組。 |
19 |
static byte[] toByteArray(char value) 返回在2元素的字節(jié)數(shù)組值大端表示;相當(dāng)于 ByteBuffer.allocate(2).putChar(value).array(). |
這個(gè)類從以下類繼承的方法:
java.lang.Object
選擇使用任何編輯器創(chuàng)建以下java程序在 C:/> Guava
GuavaTester.javaimport java.util.List; import com.google.common.primitives.Chars; public class GuavaTester { public static void main(String args[]){ GuavaTester tester = new GuavaTester(); tester.testChars(); } private void testChars(){ char[] charArray = {'a','b','c','d','e','f','g','h'}; //convert array of primitives to array of objects List<Character> objectArray = Chars.asList(charArray); System.out.println(objectArray.toString()); //convert array of objects to array of primitives charArray = Chars.toArray(objectArray); System.out.print("[ "); for(int i = 0; i< charArray.length ; i++){ System.out.print(charArray[i] + " "); } System.out.println("]"); //check if element is present in the list of primitives or not System.out.println("c is in list? "+ Chars.contains(charArray, 'c')); //return the index of element System.out.println("c position in list "+ Chars.indexOf(charArray, 'c')); //Returns the minimum System下一篇:Guava Joiner類