1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 2<!--NewPage--> 3<HTML> 4<HEAD> 5<!-- Generated by javadoc (build 1.6.0-google-internal) on Mon Jan 04 20:47:59 PST 2010 --> 6<TITLE> 7Chars (Guava Libraries 2010.01.04) 8</TITLE> 9 10<META NAME="date" CONTENT="2010-01-04"> 11 12<LINK REL ="stylesheet" TYPE="text/css" HREF="../../../../stylesheet.css" TITLE="Style"> 13 14<SCRIPT type="text/javascript"> 15function windowTitle() 16{ 17 if (location.href.indexOf('is-external=true') == -1) { 18 parent.document.title="Chars (Guava Libraries 2010.01.04)"; 19 } 20} 21</SCRIPT> 22<NOSCRIPT> 23</NOSCRIPT> 24 25</HEAD> 26 27<BODY BGCOLOR="white" onload="windowTitle();"> 28<HR> 29 30 31<!-- ========= START OF TOP NAVBAR ======= --> 32<A NAME="navbar_top"><!-- --></A> 33<A HREF="#skip-navbar_top" title="Skip navigation links"></A> 34<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY=""> 35<TR> 36<TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> 37<A NAME="navbar_top_firstrow"><!-- --></A> 38<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY=""> 39 <TR ALIGN="center" VALIGN="top"> 40 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD> 41 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD> 42 <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD> 43 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="class-use/Chars.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A> </TD> 44 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD> 45 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD> 46 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD> 47 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD> 48 </TR> 49</TABLE> 50</TD> 51<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM> 52</EM> 53</TD> 54</TR> 55 56<TR> 57<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> 58 <A HREF="../../../../com/google/common/primitives/Bytes.html" title="class in com.google.common.primitives"><B>PREV CLASS</B></A> 59 <A HREF="../../../../com/google/common/primitives/Doubles.html" title="class in com.google.common.primitives"><B>NEXT CLASS</B></A></FONT></TD> 60<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> 61 <A HREF="../../../../index.html?com/google/common/primitives/Chars.html" target="_top"><B>FRAMES</B></A> 62 <A HREF="Chars.html" target="_top"><B>NO FRAMES</B></A> 63 <SCRIPT type="text/javascript"> 64 <!-- 65 if(window==top) { 66 document.writeln('<A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A>'); 67 } 68 //--> 69</SCRIPT> 70<NOSCRIPT> 71 <A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A> 72</NOSCRIPT> 73 74 75</FONT></TD> 76</TR> 77<TR> 78<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> 79 SUMMARY: NESTED | <A HREF="#field_summary">FIELD</A> | CONSTR | <A HREF="#method_summary">METHOD</A></FONT></TD> 80<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> 81DETAIL: <A HREF="#field_detail">FIELD</A> | CONSTR | <A HREF="#method_detail">METHOD</A></FONT></TD> 82</TR> 83</TABLE> 84<A NAME="skip-navbar_top"></A> 85<!-- ========= END OF TOP NAVBAR ========= --> 86 87<HR> 88<!-- ======== START OF CLASS DATA ======== --> 89<H2> 90<FONT SIZE="-1"> 91com.google.common.primitives</FONT> 92<BR> 93Class Chars</H2> 94<PRE> 95<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">java.lang.Object</A> 96 <IMG SRC="../../../../resources/inherit.gif" ALT="extended by "><B>com.google.common.primitives.Chars</B> 97</PRE> 98<HR> 99<DL> 100<DT><PRE>public final class <B>Chars</B><DT>extends <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</A></DL> 101</PRE> 102 103<P> 104Static utility methods pertaining to <code>char</code> primitives, that are not 105 already found in either <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Character.html?is-external=true" title="class or interface in java.lang"><CODE>Character</CODE></A> or <A HREF="http://java.sun.com/javase/6/docs/api/java/util/Arrays.html?is-external=true" title="class or interface in java.util"><CODE>Arrays</CODE></A>. 106<P> 107 108<P> 109<DL> 110<DT><B>Since:</B></DT> 111 <DD>2009.09.15 <b>tentative</b></DD> 112<DT><B>Author:</B></DT> 113 <DD>Kevin Bourrillion</DD> 114</DL> 115<HR> 116 117<P> 118<!-- =========== FIELD SUMMARY =========== --> 119 120<A NAME="field_summary"><!-- --></A> 121<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""> 122<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"> 123<TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2"> 124<B>Field Summary</B></FONT></TH> 125</TR> 126<TR BGCOLOR="white" CLASS="TableRowColor"> 127<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> 128<CODE>static int</CODE></FONT></TD> 129<TD><CODE><B><A HREF="../../../../com/google/common/primitives/Chars.html#BYTES">BYTES</A></B></CODE> 130 131<BR> 132 The number of bytes required to represent a primitive <code>char</code> 133 value.</TD> 134</TR> 135</TABLE> 136 137<!-- ========== METHOD SUMMARY =========== --> 138 139<A NAME="method_summary"><!-- --></A> 140<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""> 141<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"> 142<TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2"> 143<B>Method Summary</B></FONT></TH> 144</TR> 145<TR BGCOLOR="white" CLASS="TableRowColor"> 146<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> 147<CODE>static <A HREF="http://java.sun.com/javase/6/docs/api/java/util/List.html?is-external=true" title="class or interface in java.util">List</A><<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Character.html?is-external=true" title="class or interface in java.lang">Character</A>></CODE></FONT></TD> 148<TD><CODE><B><A HREF="../../../../com/google/common/primitives/Chars.html#asList(char...)">asList</A></B>(char... backingArray)</CODE> 149 150<BR> 151 Returns a fixed-size list backed by the specified array, similar to <A HREF="http://java.sun.com/javase/6/docs/api/java/util/Arrays.html?is-external=true#asList(T...)" title="class or interface in java.util"><CODE>Arrays.asList(Object[])</CODE></A>.</TD> 152</TR> 153<TR BGCOLOR="white" CLASS="TableRowColor"> 154<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> 155<CODE>static char</CODE></FONT></TD> 156<TD><CODE><B><A HREF="../../../../com/google/common/primitives/Chars.html#checkedCast(long)">checkedCast</A></B>(long value)</CODE> 157 158<BR> 159 Returns the <code>char</code> value that is equal to <code>value</code>, if possible.</TD> 160</TR> 161<TR BGCOLOR="white" CLASS="TableRowColor"> 162<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> 163<CODE>static int</CODE></FONT></TD> 164<TD><CODE><B><A HREF="../../../../com/google/common/primitives/Chars.html#compare(char, char)">compare</A></B>(char a, 165 char b)</CODE> 166 167<BR> 168 Compares the two specified <code>char</code> values.</TD> 169</TR> 170<TR BGCOLOR="white" CLASS="TableRowColor"> 171<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> 172<CODE>static char[]</CODE></FONT></TD> 173<TD><CODE><B><A HREF="../../../../com/google/common/primitives/Chars.html#concat(char[]...)">concat</A></B>(char[]... arrays)</CODE> 174 175<BR> 176 Returns the values from each provided array combined into a single array.</TD> 177</TR> 178<TR BGCOLOR="white" CLASS="TableRowColor"> 179<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> 180<CODE>static boolean</CODE></FONT></TD> 181<TD><CODE><B><A HREF="../../../../com/google/common/primitives/Chars.html#contains(char[], char)">contains</A></B>(char[] array, 182 char target)</CODE> 183 184<BR> 185 Returns <code>true</code> if <code>target</code> is present as an element anywhere in 186 <code>array</code>.</TD> 187</TR> 188<TR BGCOLOR="white" CLASS="TableRowColor"> 189<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> 190<CODE>static char[]</CODE></FONT></TD> 191<TD><CODE><B><A HREF="../../../../com/google/common/primitives/Chars.html#ensureCapacity(char[], int, int)">ensureCapacity</A></B>(char[] array, 192 int minLength, 193 int padding)</CODE> 194 195<BR> 196 Returns an array containing the same values as <code>array</code>, but 197 guaranteed to be of a specified minimum length.</TD> 198</TR> 199<TR BGCOLOR="white" CLASS="TableRowColor"> 200<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> 201<CODE>static char</CODE></FONT></TD> 202<TD><CODE><B><A HREF="../../../../com/google/common/primitives/Chars.html#fromByteArray(byte[])">fromByteArray</A></B>(byte[] bytes)</CODE> 203 204<BR> 205 Returns the <code>char</code> value whose big-endian representation is 206 stored in the first 2 bytes of <code>bytes</code>; equivalent to <code>ByteBuffer.wrap(bytes).getChar()</code>.</TD> 207</TR> 208<TR BGCOLOR="white" CLASS="TableRowColor"> 209<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> 210<CODE>static int</CODE></FONT></TD> 211<TD><CODE><B><A HREF="../../../../com/google/common/primitives/Chars.html#hashCode(char)">hashCode</A></B>(char value)</CODE> 212 213<BR> 214 Returns a hash code for <code>value</code>; equal to the result of invoking 215 <code>((Character) value).hashCode()</code>.</TD> 216</TR> 217<TR BGCOLOR="white" CLASS="TableRowColor"> 218<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> 219<CODE>static int</CODE></FONT></TD> 220<TD><CODE><B><A HREF="../../../../com/google/common/primitives/Chars.html#indexOf(char[], char)">indexOf</A></B>(char[] array, 221 char target)</CODE> 222 223<BR> 224 Returns the index of the first appearance of the value <code>target</code> in 225 <code>array</code>.</TD> 226</TR> 227<TR BGCOLOR="white" CLASS="TableRowColor"> 228<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> 229<CODE>static int</CODE></FONT></TD> 230<TD><CODE><B><A HREF="../../../../com/google/common/primitives/Chars.html#indexOf(char[], char[])">indexOf</A></B>(char[] array, 231 char[] target)</CODE> 232 233<BR> 234 Returns the start position of the first occurrence of the specified <code>target</code> within <code>array</code>, or <code>-1</code> if there is no such occurrence.</TD> 235</TR> 236<TR BGCOLOR="white" CLASS="TableRowColor"> 237<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> 238<CODE>static <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A></CODE></FONT></TD> 239<TD><CODE><B><A HREF="../../../../com/google/common/primitives/Chars.html#join(java.lang.String, char...)">join</A></B>(<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A> separator, 240 char... array)</CODE> 241 242<BR> 243 Returns a string containing the supplied <code>char</code> values separated 244 by <code>separator</code>.</TD> 245</TR> 246<TR BGCOLOR="white" CLASS="TableRowColor"> 247<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> 248<CODE>static int</CODE></FONT></TD> 249<TD><CODE><B><A HREF="../../../../com/google/common/primitives/Chars.html#lastIndexOf(char[], char)">lastIndexOf</A></B>(char[] array, 250 char target)</CODE> 251 252<BR> 253 Returns the index of the last appearance of the value <code>target</code> in 254 <code>array</code>.</TD> 255</TR> 256<TR BGCOLOR="white" CLASS="TableRowColor"> 257<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> 258<CODE>static <A HREF="http://java.sun.com/javase/6/docs/api/java/util/Comparator.html?is-external=true" title="class or interface in java.util">Comparator</A><char[]></CODE></FONT></TD> 259<TD><CODE><B><A HREF="../../../../com/google/common/primitives/Chars.html#lexicographicalComparator()">lexicographicalComparator</A></B>()</CODE> 260 261<BR> 262 Returns a comparator that compares two <code>char</code> arrays 263 lexicographically.</TD> 264</TR> 265<TR BGCOLOR="white" CLASS="TableRowColor"> 266<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> 267<CODE>static char</CODE></FONT></TD> 268<TD><CODE><B><A HREF="../../../../com/google/common/primitives/Chars.html#max(char...)">max</A></B>(char... array)</CODE> 269 270<BR> 271 Returns the greatest value present in <code>array</code>.</TD> 272</TR> 273<TR BGCOLOR="white" CLASS="TableRowColor"> 274<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> 275<CODE>static char</CODE></FONT></TD> 276<TD><CODE><B><A HREF="../../../../com/google/common/primitives/Chars.html#min(char...)">min</A></B>(char... array)</CODE> 277 278<BR> 279 Returns the least value present in <code>array</code>.</TD> 280</TR> 281<TR BGCOLOR="white" CLASS="TableRowColor"> 282<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> 283<CODE>static char</CODE></FONT></TD> 284<TD><CODE><B><A HREF="../../../../com/google/common/primitives/Chars.html#saturatedCast(long)">saturatedCast</A></B>(long value)</CODE> 285 286<BR> 287 Returns the <code>char</code> nearest in value to <code>value</code>.</TD> 288</TR> 289<TR BGCOLOR="white" CLASS="TableRowColor"> 290<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> 291<CODE>static char[]</CODE></FONT></TD> 292<TD><CODE><B><A HREF="../../../../com/google/common/primitives/Chars.html#toArray(java.util.Collection)">toArray</A></B>(<A HREF="http://java.sun.com/javase/6/docs/api/java/util/Collection.html?is-external=true" title="class or interface in java.util">Collection</A><<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Character.html?is-external=true" title="class or interface in java.lang">Character</A>> collection)</CODE> 293 294<BR> 295 Copies a collection of <code>Character</code> instances into a new array of 296 primitive <code>char</code> values.</TD> 297</TR> 298<TR BGCOLOR="white" CLASS="TableRowColor"> 299<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> 300<CODE>static byte[]</CODE></FONT></TD> 301<TD><CODE><B><A HREF="../../../../com/google/common/primitives/Chars.html#toByteArray(char)">toByteArray</A></B>(char value)</CODE> 302 303<BR> 304 Returns a big-endian representation of <code>value</code> in a 2-element byte 305 array; equivalent to <code>ByteBuffer.allocate(2).putChar(value).array()</code>.</TD> 306</TR> 307</TABLE> 308 <A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A> 309<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""> 310<TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor"> 311<TH ALIGN="left"><B>Methods inherited from class java.lang.<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</A></B></TH> 312</TR> 313<TR BGCOLOR="white" CLASS="TableRowColor"> 314<TD><CODE><A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#clone()" title="class or interface in java.lang">clone</A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#equals(java.lang.Object)" title="class or interface in java.lang">equals</A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#finalize()" title="class or interface in java.lang">finalize</A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#getClass()" title="class or interface in java.lang">getClass</A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#hashCode()" title="class or interface in java.lang">hashCode</A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#notify()" title="class or interface in java.lang">notify</A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#notifyAll()" title="class or interface in java.lang">notifyAll</A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#toString()" title="class or interface in java.lang">toString</A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#wait()" title="class or interface in java.lang">wait</A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#wait(long)" title="class or interface in java.lang">wait</A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#wait(long, int)" title="class or interface in java.lang">wait</A></CODE></TD> 315</TR> 316</TABLE> 317 318<P> 319 320<!-- ============ FIELD DETAIL =========== --> 321 322<A NAME="field_detail"><!-- --></A> 323<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""> 324<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"> 325<TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2"> 326<B>Field Detail</B></FONT></TH> 327</TR> 328</TABLE> 329 330<A NAME="BYTES"><!-- --></A><H3> 331BYTES</H3> 332<PRE> 333public static final int <B>BYTES</B></PRE> 334<DL> 335<DD>The number of bytes required to represent a primitive <code>char</code> 336 value. 337<P> 338<DL> 339<DT><B>See Also:</B><DD><A HREF="../../../../constant-values.html#com.google.common.primitives.Chars.BYTES">Constant Field Values</A></DL> 340</DL> 341 342<!-- ============ METHOD DETAIL ========== --> 343 344<A NAME="method_detail"><!-- --></A> 345<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""> 346<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"> 347<TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2"> 348<B>Method Detail</B></FONT></TH> 349</TR> 350</TABLE> 351 352<A NAME="hashCode(char)"><!-- --></A><H3> 353hashCode</H3> 354<PRE> 355public static int <B>hashCode</B>(char value)</PRE> 356<DL> 357<DD>Returns a hash code for <code>value</code>; equal to the result of invoking 358 <code>((Character) value).hashCode()</code>. 359<P> 360<DD><DL> 361<DT><B>Parameters:</B><DD><CODE>value</CODE> - a primitive <code>char</code> value 362<DT><B>Returns:</B><DD>a hash code for the value</DL> 363</DD> 364</DL> 365<HR> 366 367<A NAME="checkedCast(long)"><!-- --></A><H3> 368checkedCast</H3> 369<PRE> 370public static char <B>checkedCast</B>(long value)</PRE> 371<DL> 372<DD>Returns the <code>char</code> value that is equal to <code>value</code>, if possible. 373<P> 374<DD><DL> 375<DT><B>Parameters:</B><DD><CODE>value</CODE> - any value in the range of the <code>char</code> type 376<DT><B>Returns:</B><DD>the <code>char</code> value that equals <code>value</code> 377<DT><B>Throws:</B> 378<DD><CODE><A HREF="http://java.sun.com/javase/6/docs/api/java/lang/IllegalArgumentException.html?is-external=true" title="class or interface in java.lang">IllegalArgumentException</A></CODE> - if <code>value</code> is greater than <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Character.html?is-external=true#MAX_VALUE" title="class or interface in java.lang"><CODE>Character.MAX_VALUE</CODE></A> or less than <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Character.html?is-external=true#MIN_VALUE" title="class or interface in java.lang"><CODE>Character.MIN_VALUE</CODE></A></DL> 379</DD> 380</DL> 381<HR> 382 383<A NAME="saturatedCast(long)"><!-- --></A><H3> 384saturatedCast</H3> 385<PRE> 386public static char <B>saturatedCast</B>(long value)</PRE> 387<DL> 388<DD>Returns the <code>char</code> nearest in value to <code>value</code>. 389<P> 390<DD><DL> 391<DT><B>Parameters:</B><DD><CODE>value</CODE> - any <code>long</code> value 392<DT><B>Returns:</B><DD>the same value cast to <code>char</code> if it is in the range of the 393 <code>char</code> type, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Character.html?is-external=true#MAX_VALUE" title="class or interface in java.lang"><CODE>Character.MAX_VALUE</CODE></A> if it is too large, 394 or <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Character.html?is-external=true#MIN_VALUE" title="class or interface in java.lang"><CODE>Character.MIN_VALUE</CODE></A> if it is too small</DL> 395</DD> 396</DL> 397<HR> 398 399<A NAME="compare(char, char)"><!-- --></A><H3> 400compare</H3> 401<PRE> 402public static int <B>compare</B>(char a, 403 char b)</PRE> 404<DL> 405<DD>Compares the two specified <code>char</code> values. The sign of the value 406 returned is the same as that of <code>((Character) a).compareTo(b)</code>. 407<P> 408<DD><DL> 409<DT><B>Parameters:</B><DD><CODE>a</CODE> - the first <code>char</code> to compare<DD><CODE>b</CODE> - the second <code>char</code> to compare 410<DT><B>Returns:</B><DD>a negative value if <code>a</code> is less than <code>b</code>; a positive 411 value if <code>a</code> is greater than <code>b</code>; or zero if they are equal</DL> 412</DD> 413</DL> 414<HR> 415 416<A NAME="contains(char[], char)"><!-- --></A><H3> 417contains</H3> 418<PRE> 419public static boolean <B>contains</B>(char[] array, 420 char target)</PRE> 421<DL> 422<DD>Returns <code>true</code> if <code>target</code> is present as an element anywhere in 423 <code>array</code>. 424<P> 425<DD><DL> 426<DT><B>Parameters:</B><DD><CODE>array</CODE> - an array of <code>char</code> values, possibly empty<DD><CODE>target</CODE> - a primitive <code>char</code> value 427<DT><B>Returns:</B><DD><code>true</code> if <code>array[i] == target</code> for some value of <code>i</code></DL> 428</DD> 429</DL> 430<HR> 431 432<A NAME="indexOf(char[], char)"><!-- --></A><H3> 433indexOf</H3> 434<PRE> 435public static int <B>indexOf</B>(char[] array, 436 char target)</PRE> 437<DL> 438<DD>Returns the index of the first appearance of the value <code>target</code> in 439 <code>array</code>. 440<P> 441<DD><DL> 442<DT><B>Parameters:</B><DD><CODE>array</CODE> - an array of <code>char</code> values, possibly empty<DD><CODE>target</CODE> - a primitive <code>char</code> value 443<DT><B>Returns:</B><DD>the least index <code>i</code> for which <code>array[i] == target</code>, or 444 <code>-1</code> if no such index exists.</DL> 445</DD> 446</DL> 447<HR> 448 449<A NAME="indexOf(char[], char[])"><!-- --></A><H3> 450indexOf</H3> 451<PRE> 452public static int <B>indexOf</B>(char[] array, 453 char[] target)</PRE> 454<DL> 455<DD>Returns the start position of the first occurrence of the specified <code>target</code> within <code>array</code>, or <code>-1</code> if there is no such occurrence. 456 457 <p>More formally, returns the lowest index <code>i</code> such that <code>java.util.Arrays.copyOfRange(array, i, i + target.length)</code> contains exactly 458 the same elements as <code>target</code>. 459<P> 460<DD><DL> 461<DT><B>Parameters:</B><DD><CODE>array</CODE> - the array to search for the sequence <code>target</code><DD><CODE>target</CODE> - the array to search for as a sub-sequence of <code>array</code></DL> 462</DD> 463</DL> 464<HR> 465 466<A NAME="lastIndexOf(char[], char)"><!-- --></A><H3> 467lastIndexOf</H3> 468<PRE> 469public static int <B>lastIndexOf</B>(char[] array, 470 char target)</PRE> 471<DL> 472<DD>Returns the index of the last appearance of the value <code>target</code> in 473 <code>array</code>. 474<P> 475<DD><DL> 476<DT><B>Parameters:</B><DD><CODE>array</CODE> - an array of <code>char</code> values, possibly empty<DD><CODE>target</CODE> - a primitive <code>char</code> value 477<DT><B>Returns:</B><DD>the greatest index <code>i</code> for which <code>array[i] == target</code>, 478 or <code>-1</code> if no such index exists.</DL> 479</DD> 480</DL> 481<HR> 482 483<A NAME="min(char...)"><!-- --></A><H3> 484min</H3> 485<PRE> 486public static char <B>min</B>(char... array)</PRE> 487<DL> 488<DD>Returns the least value present in <code>array</code>. 489<P> 490<DD><DL> 491<DT><B>Parameters:</B><DD><CODE>array</CODE> - a <i>nonempty</i> array of <code>char</code> values 492<DT><B>Returns:</B><DD>the value present in <code>array</code> that is less than or equal to 493 every other value in the array 494<DT><B>Throws:</B> 495<DD><CODE><A HREF="http://java.sun.com/javase/6/docs/api/java/lang/IllegalArgumentException.html?is-external=true" title="class or interface in java.lang">IllegalArgumentException</A></CODE> - if <code>array</code> is empty</DL> 496</DD> 497</DL> 498<HR> 499 500<A NAME="max(char...)"><!-- --></A><H3> 501max</H3> 502<PRE> 503public static char <B>max</B>(char... array)</PRE> 504<DL> 505<DD>Returns the greatest value present in <code>array</code>. 506<P> 507<DD><DL> 508<DT><B>Parameters:</B><DD><CODE>array</CODE> - a <i>nonempty</i> array of <code>char</code> values 509<DT><B>Returns:</B><DD>the value present in <code>array</code> that is greater than or equal to 510 every other value in the array 511<DT><B>Throws:</B> 512<DD><CODE><A HREF="http://java.sun.com/javase/6/docs/api/java/lang/IllegalArgumentException.html?is-external=true" title="class or interface in java.lang">IllegalArgumentException</A></CODE> - if <code>array</code> is empty</DL> 513</DD> 514</DL> 515<HR> 516 517<A NAME="concat(char[]...)"><!-- --></A><H3> 518concat</H3> 519<PRE> 520public static char[] <B>concat</B>(char[]... arrays)</PRE> 521<DL> 522<DD>Returns the values from each provided array combined into a single array. 523 For example, <code>concat(new char[] {a, b}, new char[] {}, new 524 char[] {c}</code> returns the array <code>{a, b, c}</code>. 525<P> 526<DD><DL> 527<DT><B>Parameters:</B><DD><CODE>arrays</CODE> - zero or more <code>char</code> arrays 528<DT><B>Returns:</B><DD>a single array containing all the values from the source arrays, in 529 order</DL> 530</DD> 531</DL> 532<HR> 533 534<A NAME="toByteArray(char)"><!-- --></A><H3> 535toByteArray</H3> 536<PRE> 537public static byte[] <B>toByteArray</B>(char value)</PRE> 538<DL> 539<DD>Returns a big-endian representation of <code>value</code> in a 2-element byte 540 array; equivalent to <code>ByteBuffer.allocate(2).putChar(value).array()</code>. For example, the input 541 value <code>'\\u5432'</code> would yield the byte array <code>{0x54, 0x32}</code>. 542 543 <p>If you need to convert and concatenate several values (possibly even of 544 different types), use a shared <A HREF="http://java.sun.com/javase/6/docs/api/java/nio/ByteBuffer.html?is-external=true" title="class or interface in java.nio"><CODE>ByteBuffer</CODE></A> instance, or use 545 <A HREF="../../../../com/google/common/io/ByteStreams.html#newDataOutput()"><CODE>ByteStreams.newDataOutput()</CODE></A> to get a growable 546 buffer. 547<P> 548<DD><DL> 549</DL> 550</DD> 551</DL> 552<HR> 553 554<A NAME="fromByteArray(byte[])"><!-- --></A><H3> 555fromByteArray</H3> 556<PRE> 557public static char <B>fromByteArray</B>(byte[] bytes)</PRE> 558<DL> 559<DD>Returns the <code>char</code> value whose big-endian representation is 560 stored in the first 2 bytes of <code>bytes</code>; equivalent to <code>ByteBuffer.wrap(bytes).getChar()</code>. For example, the input byte array 561 <code>{0x54, 0x32}</code> would yield the <code>char</code> value <code>'\\u5432'</code>. 562 563 <p>Arguably, it's preferable to use <A HREF="http://java.sun.com/javase/6/docs/api/java/nio/ByteBuffer.html?is-external=true" title="class or interface in java.nio"><CODE>ByteBuffer</CODE></A>; that 564 library exposes much more flexibility at little cost in readability. 565<P> 566<DD><DL> 567 568<DT><B>Throws:</B> 569<DD><CODE><A HREF="http://java.sun.com/javase/6/docs/api/java/lang/IllegalArgumentException.html?is-external=true" title="class or interface in java.lang">IllegalArgumentException</A></CODE> - if <code>bytes</code> has fewer than 2 570 elements</DL> 571</DD> 572</DL> 573<HR> 574 575<A NAME="ensureCapacity(char[], int, int)"><!-- --></A><H3> 576ensureCapacity</H3> 577<PRE> 578public static char[] <B>ensureCapacity</B>(char[] array, 579 int minLength, 580 int padding)</PRE> 581<DL> 582<DD>Returns an array containing the same values as <code>array</code>, but 583 guaranteed to be of a specified minimum length. If <code>array</code> already 584 has a length of at least <code>minLength</code>, it is returned directly. 585 Otherwise, a new array of size <code>minLength + padding</code> is returned, 586 containing the values of <code>array</code>, and zeroes in the remaining places. 587<P> 588<DD><DL> 589<DT><B>Parameters:</B><DD><CODE>array</CODE> - the source array<DD><CODE>minLength</CODE> - the minimum length the returned array must guarantee<DD><CODE>padding</CODE> - an extra amount to "grow" the array by if growth is 590 necessary 591<DT><B>Returns:</B><DD>an array containing the values of <code>array</code>, with guaranteed 592 minimum length <code>minLength</code> 593<DT><B>Throws:</B> 594<DD><CODE><A HREF="http://java.sun.com/javase/6/docs/api/java/lang/IllegalArgumentException.html?is-external=true" title="class or interface in java.lang">IllegalArgumentException</A></CODE> - if <code>minLength</code> or <code>padding</code> is 595 negative</DL> 596</DD> 597</DL> 598<HR> 599 600<A NAME="join(java.lang.String, char...)"><!-- --></A><H3> 601join</H3> 602<PRE> 603public static <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A> <B>join</B>(<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A> separator, 604 char... array)</PRE> 605<DL> 606<DD>Returns a string containing the supplied <code>char</code> values separated 607 by <code>separator</code>. For example, <code>join("-", '1', '2', '3')</code> returns 608 the string <code>"1-2-3"</code>. 609<P> 610<DD><DL> 611<DT><B>Parameters:</B><DD><CODE>separator</CODE> - the text that should appear between consecutive values in 612 the resulting string (but not at the start or end)<DD><CODE>array</CODE> - an array of <code>char</code> values, possibly empty</DL> 613</DD> 614</DL> 615<HR> 616 617<A NAME="lexicographicalComparator()"><!-- --></A><H3> 618lexicographicalComparator</H3> 619<PRE> 620public static <A HREF="http://java.sun.com/javase/6/docs/api/java/util/Comparator.html?is-external=true" title="class or interface in java.util">Comparator</A><char[]> <B>lexicographicalComparator</B>()</PRE> 621<DL> 622<DD>Returns a comparator that compares two <code>char</code> arrays 623 lexicographically. That is, it compares, using <A HREF="../../../../com/google/common/primitives/Chars.html#compare(char, char)"><CODE>compare(char, char)</CODE></A>), the first pair of values that follow any 624 common prefix, or when one array is a prefix of the other, treats the 625 shorter array as the lesser. For example, 626 <code>[] < ['a'] < ['a', 'b'] < ['b']</code>. 627 628 <p>The returned comparator is inconsistent with <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#equals(java.lang.Object)" title="class or interface in java.lang"><CODE>Object.equals(Object)</CODE></A> (since arrays support only identity equality), but 629 it is consistent with <A HREF="http://java.sun.com/javase/6/docs/api/java/util/Arrays.html?is-external=true#equals(char[], char[])" title="class or interface in java.util"><CODE>Arrays.equals(char[], char[])</CODE></A>. 630<P> 631<DD><DL> 632<DT><B>Since:</B></DT> 633 <DD>2010.01.04 <b>tentative</b></DD> 634<DT><B>See Also:</B><DD><a href="http://en.wikipedia.org/wiki/Lexicographical_order"> 635 Lexicographical order</a> article at Wikipedia</DL> 636</DD> 637</DL> 638<HR> 639 640<A NAME="toArray(java.util.Collection)"><!-- --></A><H3> 641toArray</H3> 642<PRE> 643public static char[] <B>toArray</B>(<A HREF="http://java.sun.com/javase/6/docs/api/java/util/Collection.html?is-external=true" title="class or interface in java.util">Collection</A><<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Character.html?is-external=true" title="class or interface in java.lang">Character</A>> collection)</PRE> 644<DL> 645<DD>Copies a collection of <code>Character</code> instances into a new array of 646 primitive <code>char</code> values. 647 648 <p>Elements are copied from the argument collection as if by <code>collection.toArray()</code>. Calling this method is as thread-safe as calling 649 that method. 650<P> 651<DD><DL> 652<DT><B>Parameters:</B><DD><CODE>collection</CODE> - a collection of <code>Character</code> objects 653<DT><B>Returns:</B><DD>an array containing the same values as <code>collection</code>, in the 654 same order, converted to primitives 655<DT><B>Throws:</B> 656<DD><CODE><A HREF="http://java.sun.com/javase/6/docs/api/java/lang/NullPointerException.html?is-external=true" title="class or interface in java.lang">NullPointerException</A></CODE> - if <code>collection</code> or any of its elements 657 is null</DL> 658</DD> 659</DL> 660<HR> 661 662<A NAME="asList(char...)"><!-- --></A><H3> 663asList</H3> 664<PRE> 665public static <A HREF="http://java.sun.com/javase/6/docs/api/java/util/List.html?is-external=true" title="class or interface in java.util">List</A><<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Character.html?is-external=true" title="class or interface in java.lang">Character</A>> <B>asList</B>(char... backingArray)</PRE> 666<DL> 667<DD>Returns a fixed-size list backed by the specified array, similar to <A HREF="http://java.sun.com/javase/6/docs/api/java/util/Arrays.html?is-external=true#asList(T...)" title="class or interface in java.util"><CODE>Arrays.asList(Object[])</CODE></A>. The list supports <A HREF="http://java.sun.com/javase/6/docs/api/java/util/List.html?is-external=true#set(int, E)" title="class or interface in java.util"><CODE>List.set(int, Object)</CODE></A>, 668 but any attempt to set a value to <code>null</code> will result in a <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/NullPointerException.html?is-external=true" title="class or interface in java.lang"><CODE>NullPointerException</CODE></A>. 669 670 <p>The returned list maintains the values, but not the identities, of 671 <code>Character</code> objects written to or read from it. For example, whether 672 <code>list.get(0) == list.get(0)</code> is true for the returned list is 673 unspecified. 674<P> 675<DD><DL> 676<DT><B>Parameters:</B><DD><CODE>backingArray</CODE> - the array to back the list 677<DT><B>Returns:</B><DD>a list view of the array</DL> 678</DD> 679</DL> 680<!-- ========= END OF CLASS DATA ========= --> 681<HR> 682 683 684<!-- ======= START OF BOTTOM NAVBAR ====== --> 685<A NAME="navbar_bottom"><!-- --></A> 686<A HREF="#skip-navbar_bottom" title="Skip navigation links"></A> 687<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY=""> 688<TR> 689<TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> 690<A NAME="navbar_bottom_firstrow"><!-- --></A> 691<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY=""> 692 <TR ALIGN="center" VALIGN="top"> 693 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD> 694 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD> 695 <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD> 696 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="class-use/Chars.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A> </TD> 697 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD> 698 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD> 699 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD> 700 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD> 701 </TR> 702</TABLE> 703</TD> 704<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM> 705</EM> 706</TD> 707</TR> 708 709<TR> 710<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> 711 <A HREF="../../../../com/google/common/primitives/Bytes.html" title="class in com.google.common.primitives"><B>PREV CLASS</B></A> 712 <A HREF="../../../../com/google/common/primitives/Doubles.html" title="class in com.google.common.primitives"><B>NEXT CLASS</B></A></FONT></TD> 713<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> 714 <A HREF="../../../../index.html?com/google/common/primitives/Chars.html" target="_top"><B>FRAMES</B></A> 715 <A HREF="Chars.html" target="_top"><B>NO FRAMES</B></A> 716 <SCRIPT type="text/javascript"> 717 <!-- 718 if(window==top) { 719 document.writeln('<A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A>'); 720 } 721 //--> 722</SCRIPT> 723<NOSCRIPT> 724 <A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A> 725</NOSCRIPT> 726 727 728</FONT></TD> 729</TR> 730<TR> 731<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> 732 SUMMARY: NESTED | <A HREF="#field_summary">FIELD</A> | CONSTR | <A HREF="#method_summary">METHOD</A></FONT></TD> 733<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> 734DETAIL: <A HREF="#field_detail">FIELD</A> | CONSTR | <A HREF="#method_detail">METHOD</A></FONT></TD> 735</TR> 736</TABLE> 737<A NAME="skip-navbar_bottom"></A> 738<!-- ======== END OF BOTTOM NAVBAR ======= --> 739 740<HR> 741 742</BODY> 743</HTML> 744