This class contains various methods for manipulating arrays (such as sorting and searching). This class also contains a static factory that allows arrays to ...
Overview
Package
Class
Use
Tree
Deprecated
Index
Help
Java™ PlatformStandard Ed. 7
PrevClass
NextClass
Frames
NoFrames
AllClasses
Summary:
Nested |
Field |
Constr |
Method
Detail:
Field |
Constr |
Method
java.lang.Object
java.util.Arrays
publicclassArrays
extendsObject
Thisclasscontainsvariousmethodsformanipulatingarrays(suchas
sortingandsearching).Thisclassalsocontainsastaticfactory
thatallowsarraystobeviewedaslists.
ThemethodsinthisclassallthrowaNullPointerException,
ifthespecifiedarrayreferenceisnull,exceptwherenoted.
Thedocumentationforthemethodscontainedinthisclassincludes
briefsdescriptionoftheimplementations.Suchdescriptionsshould
beregardedasimplementationnotes,ratherthanpartsofthe
specification.Implementorsshouldfeelfreetosubstituteother
algorithms,solongasthespecificationitselfisadheredto.(For
example,thealgorithmusedbysort(Object[])doesnothavetobe
aMergeSort,butitdoeshavetobestable.)
Thisclassisamemberofthe
JavaCollectionsFramework.
Since:
1.2
MethodSummary
Methods
ModifierandType
MethodandDescription
static List
asList(T... a)
Returnsafixed-sizelistbackedbythespecifiedarray.
staticint
binarySearch(byte[] a,
byte key)
Searchesthespecifiedarrayofbytesforthespecifiedvalueusingthe
binarysearchalgorithm.
staticint
binarySearch(byte[] a,
int fromIndex,
int toIndex,
byte key)
Searchesarangeof
thespecifiedarrayofbytesforthespecifiedvalueusingthe
binarysearchalgorithm.
staticint
binarySearch(char[] a,
char key)
Searchesthespecifiedarrayofcharsforthespecifiedvalueusingthe
binarysearchalgorithm.
staticint
binarySearch(char[] a,
int fromIndex,
int toIndex,
char key)
Searchesarangeof
thespecifiedarrayofcharsforthespecifiedvalueusingthe
binarysearchalgorithm.
staticint
binarySearch(double[] a,
double key)
Searchesthespecifiedarrayofdoublesforthespecifiedvalueusing
thebinarysearchalgorithm.
staticint
binarySearch(double[] a,
int fromIndex,
int toIndex,
double key)
Searchesarangeof
thespecifiedarrayofdoublesforthespecifiedvalueusing
thebinarysearchalgorithm.
staticint
binarySearch(float[] a,
float key)
Searchesthespecifiedarrayoffloatsforthespecifiedvalueusing
thebinarysearchalgorithm.
staticint
binarySearch(float[] a,
int fromIndex,
int toIndex,
float key)
Searchesarangeof
thespecifiedarrayoffloatsforthespecifiedvalueusing
thebinarysearchalgorithm.
staticint
binarySearch(int[] a,
int key)
Searchesthespecifiedarrayofintsforthespecifiedvalueusingthe
binarysearchalgorithm.
staticint
binarySearch(int[] a,
int fromIndex,
int toIndex,
int key)
Searchesarangeof
thespecifiedarrayofintsforthespecifiedvalueusingthe
binarysearchalgorithm.
staticint
binarySearch(long[] a,
int fromIndex,
int toIndex,
long key)
Searchesarangeof
thespecifiedarrayoflongsforthespecifiedvalueusingthe
binarysearchalgorithm.
staticint
binarySearch(long[] a,
long key)
Searchesthespecifiedarrayoflongsforthespecifiedvalueusingthe
binarysearchalgorithm.
staticint
binarySearch(Object[] a,
int fromIndex,
int toIndex,
Object key)
Searchesarangeof
thespecifiedarrayforthespecifiedobjectusingthebinary
searchalgorithm.
staticint
binarySearch(Object[] a,
Object key)
Searchesthespecifiedarrayforthespecifiedobjectusingthebinary
searchalgorithm.
staticint
binarySearch(short[] a,
int fromIndex,
int toIndex,
short key)
Searchesarangeof
thespecifiedarrayofshortsforthespecifiedvalueusing
thebinarysearchalgorithm.
staticint
binarySearch(short[] a,
short key)
Searchesthespecifiedarrayofshortsforthespecifiedvalueusing
thebinarysearchalgorithm.
static int
binarySearch(T[] a,
int fromIndex,
int toIndex,
T key,
Comparator c)
Searchesarangeof
thespecifiedarrayforthespecifiedobjectusingthebinary
searchalgorithm.
static int
binarySearch(T[] a,
T key,
Comparator c)
Searchesthespecifiedarrayforthespecifiedobjectusingthebinary
searchalgorithm.
staticboolean[]
copyOf(boolean[] original,
int newLength)
Copiesthespecifiedarray,truncatingorpaddingwithfalse(ifnecessary)
sothecopyhasthespecifiedlength.
staticbyte[]
copyOf(byte[] original,
int newLength)
Copiesthespecifiedarray,truncatingorpaddingwithzeros(ifnecessary)
sothecopyhasthespecifiedlength.
staticchar[]
copyOf(char[] original,
int newLength)
Copiesthespecifiedarray,truncatingorpaddingwithnullcharacters(ifnecessary)
sothecopyhasthespecifiedlength.
staticdouble[]
copyOf(double[] original,
int newLength)
Copiesthespecifiedarray,truncatingorpaddingwithzeros(ifnecessary)
sothecopyhasthespecifiedlength.
staticfloat[]
copyOf(float[] original,
int newLength)
Copiesthespecifiedarray,truncatingorpaddingwithzeros(ifnecessary)
sothecopyhasthespecifiedlength.
staticint[]
copyOf(int[] original,
int newLength)
Copiesthespecifiedarray,truncatingorpaddingwithzeros(ifnecessary)
sothecopyhasthespecifiedlength.
staticlong[]
copyOf(long[] original,
int newLength)
Copiesthespecifiedarray,truncatingorpaddingwithzeros(ifnecessary)
sothecopyhasthespecifiedlength.
staticshort[]
copyOf(short[] original,
int newLength)
Copiesthespecifiedarray,truncatingorpaddingwithzeros(ifnecessary)
sothecopyhasthespecifiedlength.
static T[]
copyOf(T[] original,
int newLength)
Copiesthespecifiedarray,truncatingorpaddingwithnulls(ifnecessary)
sothecopyhasthespecifiedlength.
static T[]
copyOf(U[] original,
int newLength,
Class newType)
Copiesthespecifiedarray,truncatingorpaddingwithnulls(ifnecessary)
sothecopyhasthespecifiedlength.
staticboolean[]
copyOfRange(boolean[] original,
int from,
int to)
Copiesthespecifiedrangeofthespecifiedarrayintoanewarray.
staticbyte[]
copyOfRange(byte[] original,
int from,
int to)
Copiesthespecifiedrangeofthespecifiedarrayintoanewarray.
staticchar[]
copyOfRange(char[] original,
int from,
int to)
Copiesthespecifiedrangeofthespecifiedarrayintoanewarray.
staticdouble[]
copyOfRange(double[] original,
int from,
int to)
Copiesthespecifiedrangeofthespecifiedarrayintoanewarray.
staticfloat[]
copyOfRange(float[] original,
int from,
int to)
Copiesthespecifiedrangeofthespecifiedarrayintoanewarray.
staticint[]
copyOfRange(int[] original,
int from,
int to)
Copiesthespecifiedrangeofthespecifiedarrayintoanewarray.
staticlong[]
copyOfRange(long[] original,
int from,
int to)
Copiesthespecifiedrangeofthespecifiedarrayintoanewarray.
staticshort[]
copyOfRange(short[] original,
int from,
int to)
Copiesthespecifiedrangeofthespecifiedarrayintoanewarray.
static T[]
copyOfRange(T[] original,
int from,
int to)
Copiesthespecifiedrangeofthespecifiedarrayintoanewarray.
static T[]
copyOfRange(U[] original,
int from,
int to,
Class newType)
Copiesthespecifiedrangeofthespecifiedarrayintoanewarray.
staticboolean
deepEquals(Object[] a1,
Object[] a2)
Returnstrueifthetwospecifiedarraysaredeeply
equaltooneanother.
staticint
deepHashCode(Object[] a)
Returnsahashcodebasedonthe"deepcontents"ofthespecified
array.
staticString
deepToString(Object[] a)
Returnsastringrepresentationofthe"deepcontents"ofthespecified
array.
staticboolean
equals(boolean[] a,
boolean[] a2)
Returnstrueifthetwospecifiedarraysofbooleansare
equaltooneanother.
staticboolean
equals(byte[] a,
byte[] a2)
Returnstrueifthetwospecifiedarraysofbytesare
equaltooneanother.
staticboolean
equals(char[] a,
char[] a2)
Returnstrueifthetwospecifiedarraysofcharsare
equaltooneanother.
staticboolean
equals(double[] a,
double[] a2)
Returnstrueifthetwospecifiedarraysofdoublesare
equaltooneanother.
staticboolean
equals(float[] a,
float[] a2)
Returnstrueifthetwospecifiedarraysoffloatsare
equaltooneanother.
staticboolean
equals(int[] a,
int[] a2)
Returnstrueifthetwospecifiedarraysofintsare
equaltooneanother.
staticboolean
equals(long[] a,
long[] a2)
Returnstrueifthetwospecifiedarraysoflongsare
equaltooneanother.
staticboolean
equals(Object[] a,
Object[] a2)
ReturnstrueifthetwospecifiedarraysofObjectsare
equaltooneanother.
staticboolean
equals(short[] a,
short[] a2)
Returnstrueifthetwospecifiedarraysofshortsare
equaltooneanother.
staticvoid
fill(boolean[] a,
boolean val)
Assignsthespecifiedbooleanvaluetoeachelementofthespecified
arrayofbooleans.
staticvoid
fill(boolean[] a,
int fromIndex,
int toIndex,
boolean val)
Assignsthespecifiedbooleanvaluetoeachelementofthespecified
rangeofthespecifiedarrayofbooleans.
staticvoid
fill(byte[] a,
byte val)
Assignsthespecifiedbytevaluetoeachelementofthespecifiedarray
ofbytes.
staticvoid
fill(byte[] a,
int fromIndex,
int toIndex,
byte val)
Assignsthespecifiedbytevaluetoeachelementofthespecified
rangeofthespecifiedarrayofbytes.
staticvoid
fill(char[] a,
char val)
Assignsthespecifiedcharvaluetoeachelementofthespecifiedarray
ofchars.
staticvoid
fill(char[] a,
int fromIndex,
int toIndex,
char val)
Assignsthespecifiedcharvaluetoeachelementofthespecified
rangeofthespecifiedarrayofchars.
staticvoid
fill(double[] a,
double val)
Assignsthespecifieddoublevaluetoeachelementofthespecified
arrayofdoubles.
staticvoid
fill(double[] a,
int fromIndex,
int toIndex,
double val)
Assignsthespecifieddoublevaluetoeachelementofthespecified
rangeofthespecifiedarrayofdoubles.
staticvoid
fill(float[] a,
float val)
Assignsthespecifiedfloatvaluetoeachelementofthespecifiedarray
offloats.
staticvoid
fill(float[] a,
int fromIndex,
int toIndex,
float val)
Assignsthespecifiedfloatvaluetoeachelementofthespecified
rangeofthespecifiedarrayoffloats.
staticvoid
fill(int[] a,
int val)
Assignsthespecifiedintvaluetoeachelementofthespecifiedarray
ofints.
staticvoid
fill(int[] a,
int fromIndex,
int toIndex,
int val)
Assignsthespecifiedintvaluetoeachelementofthespecified
rangeofthespecifiedarrayofints.
staticvoid
fill(long[] a,
int fromIndex,
int toIndex,
long val)
Assignsthespecifiedlongvaluetoeachelementofthespecified
rangeofthespecifiedarrayoflongs.
staticvoid
fill(long[] a,
long val)
Assignsthespecifiedlongvaluetoeachelementofthespecifiedarray
oflongs.
staticvoid
fill(Object[] a,
int fromIndex,
int toIndex,
Object val)
AssignsthespecifiedObjectreferencetoeachelementofthespecified
rangeofthespecifiedarrayofObjects.
staticvoid
fill(Object[] a,
Object val)
AssignsthespecifiedObjectreferencetoeachelementofthespecified
arrayofObjects.
staticvoid
fill(short[] a,
int fromIndex,
int toIndex,
short val)
Assignsthespecifiedshortvaluetoeachelementofthespecified
rangeofthespecifiedarrayofshorts.
staticvoid
fill(short[] a,
short val)
Assignsthespecifiedshortvaluetoeachelementofthespecifiedarray
ofshorts.
staticint
hashCode(boolean[] a)
Returnsahashcodebasedonthecontentsofthespecifiedarray.
staticint
hashCode(byte[] a)
Returnsahashcodebasedonthecontentsofthespecifiedarray.
staticint
hashCode(char[] a)
Returnsahashcodebasedonthecontentsofthespecifiedarray.
staticint
hashCode(double[] a)
Returnsahashcodebasedonthecontentsofthespecifiedarray.
staticint
hashCode(float[] a)
Returnsahashcodebasedonthecontentsofthespecifiedarray.
staticint
hashCode(int[] a)
Returnsahashcodebasedonthecontentsofthespecifiedarray.
staticint
hashCode(long[] a)
Returnsahashcodebasedonthecontentsofthespecifiedarray.
staticint
hashCode(Object[] a)
Returnsahashcodebasedonthecontentsofthespecifiedarray.
staticint
hashCode(short[] a)
Returnsahashcodebasedonthecontentsofthespecifiedarray.
staticvoid
sort(byte[] a)
Sortsthespecifiedarrayintoascendingnumericalorder.
staticvoid
sort(byte[] a,
int fromIndex,
int toIndex)
Sortsthespecifiedrangeofthearrayintoascendingorder.
staticvoid
sort(char[] a)
Sortsthespecifiedarrayintoascendingnumericalorder.
staticvoid
sort(char[] a,
int fromIndex,
int toIndex)
Sortsthespecifiedrangeofthearrayintoascendingorder.
staticvoid
sort(double[] a)
Sortsthespecifiedarrayintoascendingnumericalorder.
staticvoid
sort(double[] a,
int fromIndex,
int toIndex)
Sortsthespecifiedrangeofthearrayintoascendingorder.
staticvoid
sort(float[] a)
Sortsthespecifiedarrayintoascendingnumericalorder.
staticvoid
sort(float[] a,
int fromIndex,
int toIndex)
Sortsthespecifiedrangeofthearrayintoascendingorder.
staticvoid
sort(int[] a)
Sortsthespecifiedarrayintoascendingnumericalorder.
staticvoid
sort(int[] a,
int fromIndex,
int toIndex)
Sortsthespecifiedrangeofthearrayintoascendingorder.
staticvoid
sort(long[] a)
Sortsthespecifiedarrayintoascendingnumericalorder.
staticvoid
sort(long[] a,
int fromIndex,
int toIndex)
Sortsthespecifiedrangeofthearrayintoascendingorder.
staticvoid
sort(Object[] a)
Sortsthespecifiedarrayofobjectsintoascendingorder,according
tothenaturalorderingofitselements.
staticvoid
sort(Object[] a,
int fromIndex,
int toIndex)
Sortsthespecifiedrangeofthespecifiedarrayofobjectsinto
ascendingorder,accordingtothe
naturalorderingofits
elements.
staticvoid
sort(short[] a)
Sortsthespecifiedarrayintoascendingnumericalorder.
staticvoid
sort(short[] a,
int fromIndex,
int toIndex)
Sortsthespecifiedrangeofthearrayintoascendingorder.
static void
sort(T[] a,
Comparator c)
Sortsthespecifiedarrayofobjectsaccordingtotheorderinducedby
thespecifiedcomparator.
static void
sort(T[] a,
int fromIndex,
int toIndex,
Comparator c)
Sortsthespecifiedrangeofthespecifiedarrayofobjectsaccording
totheorderinducedbythespecifiedcomparator.
staticString
toString(boolean[] a)
Returnsastringrepresentationofthecontentsofthespecifiedarray.
staticString
toString(byte[] a)
Returnsastringrepresentationofthecontentsofthespecifiedarray.
staticString
toString(char[] a)
Returnsastringrepresentationofthecontentsofthespecifiedarray.
staticString
toString(double[] a)
Returnsastringrepresentationofthecontentsofthespecifiedarray.
staticString
toString(float[] a)
Returnsastringrepresentationofthecontentsofthespecifiedarray.
staticString
toString(int[] a)
Returnsastringrepresentationofthecontentsofthespecifiedarray.
staticString
toString(long[] a)
Returnsastringrepresentationofthecontentsofthespecifiedarray.
staticString
toString(Object[] a)
Returnsastringrepresentationofthecontentsofthespecifiedarray.
staticString
toString(short[] a)
Returnsastringrepresentationofthecontentsofthespecifiedarray.
Methodsinheritedfromclass java.lang.Object
clone,equals,finalize,getClass,hashCode,notify,notifyAll,toString,wait,wait,wait
MethodDetail
sort
publicstatic void sort(int[] a)
Sortsthespecifiedarrayintoascendingnumericalorder.
Implementationnote:ThesortingalgorithmisaDual-PivotQuicksort
byVladimirYaroslavskiy,JonBentley,andJoshuaBloch.Thisalgorithm
offersO(nlog(n))performanceonmanydatasetsthatcauseother
quicksortstodegradetoquadraticperformance,andistypically
fasterthantraditional(one-pivot)Quicksortimplementations.
Parameters:a-thearraytobesorted
sort
publicstatic void sort(int[] a,
int fromIndex,
int toIndex)
Sortsthespecifiedrangeofthearrayintoascendingorder.Therange
tobesortedextendsfromtheindexfromIndex,inclusive,to
theindextoIndex,exclusive.IffromIndex==toIndex,
therangetobesortedisempty.
Implementationnote:ThesortingalgorithmisaDual-PivotQuicksort
byVladimirYaroslavskiy,JonBentley,andJoshuaBloch.Thisalgorithm
offersO(nlog(n))performanceonmanydatasetsthatcauseother
quicksortstodegradetoquadraticperformance,andistypically
fasterthantraditional(one-pivot)Quicksortimplementations.
Parameters:a-thearraytobesortedfromIndex-theindexofthefirstelement,inclusive,tobesortedtoIndex-theindexofthelastelement,exclusive,tobesorted
Throws:
IllegalArgumentException-iffromIndex>toIndex
ArrayIndexOutOfBoundsException-iffromIndex<0ortoIndex>a.length
sort
publicstatic void sort(long[] a)
Sortsthespecifiedarrayintoascendingnumericalorder.
Implementationnote:ThesortingalgorithmisaDual-PivotQuicksort
byVladimirYaroslavskiy,JonBentley,andJoshuaBloch.Thisalgorithm
offersO(nlog(n))performanceonmanydatasetsthatcauseother
quicksortstodegradetoquadraticperformance,andistypically
fasterthantraditional(one-pivot)Quicksortimplementations.
Parameters:a-thearraytobesorted
sort
publicstatic void sort(long[] a,
int fromIndex,
int toIndex)
Sortsthespecifiedrangeofthearrayintoascendingorder.Therange
tobesortedextendsfromtheindexfromIndex,inclusive,to
theindextoIndex,exclusive.IffromIndex==toIndex,
therangetobesortedisempty.
Implementationnote:ThesortingalgorithmisaDual-PivotQuicksort
byVladimirYaroslavskiy,JonBentley,andJoshuaBloch.Thisalgorithm
offersO(nlog(n))performanceonmanydatasetsthatcauseother
quicksortstodegradetoquadraticperformance,andistypically
fasterthantraditional(one-pivot)Quicksortimplementations.
Parameters:a-thearraytobesortedfromIndex-theindexofthefirstelement,inclusive,tobesortedtoIndex-theindexofthelastelement,exclusive,tobesorted
Throws:
IllegalArgumentException-iffromIndex>toIndex
ArrayIndexOutOfBoundsException-iffromIndex<0ortoIndex>a.length
sort
publicstatic void sort(short[] a)
Sortsthespecifiedarrayintoascendingnumericalorder.
Implementationnote:ThesortingalgorithmisaDual-PivotQuicksort
byVladimirYaroslavskiy,JonBentley,andJoshuaBloch.Thisalgorithm
offersO(nlog(n))performanceonmanydatasetsthatcauseother
quicksortstodegradetoquadraticperformance,andistypically
fasterthantraditional(one-pivot)Quicksortimplementations.
Parameters:a-thearraytobesorted
sort
publicstatic void sort(short[] a,
int fromIndex,
int toIndex)
Sortsthespecifiedrangeofthearrayintoascendingorder.Therange
tobesortedextendsfromtheindexfromIndex,inclusive,to
theindextoIndex,exclusive.IffromIndex==toIndex,
therangetobesortedisempty.
Implementationnote:ThesortingalgorithmisaDual-PivotQuicksort
byVladimirYaroslavskiy,JonBentley,andJoshuaBloch.Thisalgorithm
offersO(nlog(n))performanceonmanydatasetsthatcauseother
quicksortstodegradetoquadraticperformance,andistypically
fasterthantraditional(one-pivot)Quicksortimplementations.
Parameters:a-thearraytobesortedfromIndex-theindexofthefirstelement,inclusive,tobesortedtoIndex-theindexofthelastelement,exclusive,tobesorted
Throws:
IllegalArgumentException-iffromIndex>toIndex
ArrayIndexOutOfBoundsException-iffromIndex<0ortoIndex>a.length
sort
publicstatic void sort(char[] a)
Sortsthespecifiedarrayintoascendingnumericalorder.
Implementationnote:ThesortingalgorithmisaDual-PivotQuicksort
byVladimirYaroslavskiy,JonBentley,andJoshuaBloch.Thisalgorithm
offersO(nlog(n))performanceonmanydatasetsthatcauseother
quicksortstodegradetoquadraticperformance,andistypically
fasterthantraditional(one-pivot)Quicksortimplementations.
Parameters:a-thearraytobesorted
sort
publicstatic void sort(char[] a,
int fromIndex,
int toIndex)
Sortsthespecifiedrangeofthearrayintoascendingorder.Therange
tobesortedextendsfromtheindexfromIndex,inclusive,to
theindextoIndex,exclusive.IffromIndex==toIndex,
therangetobesortedisempty.
Implementationnote:ThesortingalgorithmisaDual-PivotQuicksort
byVladimirYaroslavskiy,JonBentley,andJoshuaBloch.Thisalgorithm
offersO(nlog(n))performanceonmanydatasetsthatcauseother
quicksortstodegradetoquadraticperformance,andistypically
fasterthantraditional(one-pivot)Quicksortimplementations.
Parameters:a-thearraytobesortedfromIndex-theindexofthefirstelement,inclusive,tobesortedtoIndex-theindexofthelastelement,exclusive,tobesorted
Throws:
IllegalArgumentException-iffromIndex>toIndex
ArrayIndexOutOfBoundsException-iffromIndex<0ortoIndex>a.length
sort
publicstatic void sort(byte[] a)
Sortsthespecifiedarrayintoascendingnumericalorder.
Implementationnote:ThesortingalgorithmisaDual-PivotQuicksort
byVladimirYaroslavskiy,JonBentley,andJoshuaBloch.Thisalgorithm
offersO(nlog(n))performanceonmanydatasetsthatcauseother
quicksortstodegradetoquadraticperformance,andistypically
fasterthantraditional(one-pivot)Quicksortimplementations.
Parameters:a-thearraytobesorted
sort
publicstatic void sort(byte[] a,
int fromIndex,
int toIndex)
Sortsthespecifiedrangeofthearrayintoascendingorder.Therange
tobesortedextendsfromtheindexfromIndex,inclusive,to
theindextoIndex,exclusive.IffromIndex==toIndex,
therangetobesortedisempty.
Implementationnote:ThesortingalgorithmisaDual-PivotQuicksort
byVladimirYaroslavskiy,JonBentley,andJoshuaBloch.Thisalgorithm
offersO(nlog(n))performanceonmanydatasetsthatcauseother
quicksortstodegradetoquadraticperformance,andistypically
fasterthantraditional(one-pivot)Quicksortimplementations.
Parameters:a-thearraytobesortedfromIndex-theindexofthefirstelement,inclusive,tobesortedtoIndex-theindexofthelastelement,exclusive,tobesorted
Throws:
IllegalArgumentException-iffromIndex>toIndex
ArrayIndexOutOfBoundsException-iffromIndex<0ortoIndex>a.length
sort
publicstatic void sort(float[] a)
Sortsthespecifiedarrayintoascendingnumericalorder.
ThetoIndex
ArrayIndexOutOfBoundsException-iffromIndex<0ortoIndex>a.length
sort
publicstatic void sort(double[] a)
Sortsthespecifiedarrayintoascendingnumericalorder.
ThetoIndex
ArrayIndexOutOfBoundsException-iffromIndex<0ortoIndex>a.length
sort
publicstatic void sort(Object[] a)
Sortsthespecifiedarrayofobjectsintoascendingorder,according
tothenaturalorderingofitselements.
AllelementsinthearraymustimplementtheComparable
interface.Furthermore,allelementsinthearraymustbe
mutuallycomparable(thatis,e1.compareTo(e2)must
notthrowaClassCastExceptionforanyelementse1
ande2inthearray).
Thissortisguaranteedtobestable:equalelementswill
notbereorderedasaresultofthesort.
Implementationnote:Thisimplementationisastable,adaptive,
iterativemergesortthatrequiresfarfewerthannlg(n)comparisons
whentheinputarrayispartiallysorted,whileofferingthe
performanceofatraditionalmergesortwhentheinputarrayis
randomlyordered.Iftheinputarrayisnearlysorted,the
implementationrequiresapproximatelyncomparisons.Temporary
storagerequirementsvaryfromasmallconstantfornearlysorted
inputarrayston/2objectreferencesforrandomlyorderedinput
arrays.
Theimplementationtakesequaladvantageofascendingand
descendingorderinitsinputarray,andcantakeadvantageof
ascendinganddescendingorderindifferentpartsofthethesame
inputarray.Itiswell-suitedtomergingtwoormoresortedarrays:
simplyconcatenatethearraysandsorttheresultingarray.
TheimplementationwasadaptedfromTimPeters'slistsortforPython
(
TimSort).ItusestechiquesfromPeterMcIlroy's"Optimistic
SortingandInformationTheoreticComplexity",inProceedingsofthe
FourthAnnualACM-SIAMSymposiumonDiscreteAlgorithms,pp467-474,
January1993.
Parameters:a-thearraytobesorted
Throws:
ClassCastException-ifthearraycontainselementsthatarenot
mutuallycomparable(forexample,stringsandintegers)
IllegalArgumentException-(optional)ifthenatural
orderingofthearrayelementsisfoundtoviolatethe
Comparablecontract
sort
publicstatic void sort(Object[] a,
int fromIndex,
int toIndex)
Sortsthespecifiedrangeofthespecifiedarrayofobjectsinto
ascendingorder,accordingtothe
naturalorderingofits
elements.Therangetobesortedextendsfromindex
fromIndex,inclusive,toindextoIndex,exclusive.
(IffromIndex==toIndex,therangetobesortedisempty.)All
elementsinthisrangemustimplementtheComparable
interface.Furthermore,allelementsinthisrangemustbemutually
comparable(thatis,e1.compareTo(e2)mustnotthrowa
ClassCastExceptionforanyelementse1and
e2inthearray).
Thissortisguaranteedtobestable:equalelementswill
notbereorderedasaresultofthesort.
Implementationnote:Thisimplementationisastable,adaptive,
iterativemergesortthatrequiresfarfewerthannlg(n)comparisons
whentheinputarrayispartiallysorted,whileofferingthe
performanceofatraditionalmergesortwhentheinputarrayis
randomlyordered.Iftheinputarrayisnearlysorted,the
implementationrequiresapproximatelyncomparisons.Temporary
storagerequirementsvaryfromasmallconstantfornearlysorted
inputarrayston/2objectreferencesforrandomlyorderedinput
arrays.
Theimplementationtakesequaladvantageofascendingand
descendingorderinitsinputarray,andcantakeadvantageof
ascendinganddescendingorderindifferentpartsofthethesame
inputarray.Itiswell-suitedtomergingtwoormoresortedarrays:
simplyconcatenatethearraysandsorttheresultingarray.
TheimplementationwasadaptedfromTimPeters'slistsortforPython
(
TimSort).ItusestechiquesfromPeterMcIlroy's"Optimistic
SortingandInformationTheoreticComplexity",inProceedingsofthe
FourthAnnualACM-SIAMSymposiumonDiscreteAlgorithms,pp467-474,
January1993.
Parameters:a-thearraytobesortedfromIndex-theindexofthefirstelement(inclusive)tobe
sortedtoIndex-theindexofthelastelement(exclusive)tobesorted
Throws:
IllegalArgumentException-iffromIndex>toIndexor
(optional)ifthenaturalorderingofthearrayelementsis
foundtoviolatetheComparablecontract
ArrayIndexOutOfBoundsException-iffromIndex<0or
toIndex>a.length
ClassCastException-ifthearraycontainselementsthatare
notmutuallycomparable(forexample,stringsand
integers).
sort
publicstatic void sort(T[] a,
Comparator c)
Sortsthespecifiedarrayofobjectsaccordingtotheorderinducedby
thespecifiedcomparator.Allelementsinthearraymustbe
mutuallycomparablebythespecifiedcomparator(thatis,
c.compare(e1,e2)mustnotthrowaClassCastException
foranyelementse1ande2inthearray).
Thissortisguaranteedtobestable:equalelementswill
notbereorderedasaresultofthesort.
Implementationnote:Thisimplementationisastable,adaptive,
iterativemergesortthatrequiresfarfewerthannlg(n)comparisons
whentheinputarrayispartiallysorted,whileofferingthe
performanceofatraditionalmergesortwhentheinputarrayis
randomlyordered.Iftheinputarrayisnearlysorted,the
implementationrequiresapproximatelyncomparisons.Temporary
storagerequirementsvaryfromasmallconstantfornearlysorted
inputarrayston/2objectreferencesforrandomlyorderedinput
arrays.
Theimplementationtakesequaladvantageofascendingand
descendingorderinitsinputarray,andcantakeadvantageof
ascendinganddescendingorderindifferentpartsofthethesame
inputarray.Itiswell-suitedtomergingtwoormoresortedarrays:
simplyconcatenatethearraysandsorttheresultingarray.
TheimplementationwasadaptedfromTimPeters'slistsortforPython
(
TimSort).ItusestechiquesfromPeterMcIlroy's"Optimistic
SortingandInformationTheoreticComplexity",inProceedingsofthe
FourthAnnualACM-SIAMSymposiumonDiscreteAlgorithms,pp467-474,
January1993.
Parameters:a-thearraytobesortedc-thecomparatortodeterminetheorderofthearray.A
nullvalueindicatesthattheelements'
naturalorderingshouldbeused.
Throws:
ClassCastException-ifthearraycontainselementsthatare
notmutuallycomparableusingthespecifiedcomparator
IllegalArgumentException-(optional)ifthecomparatoris
foundtoviolatetheComparatorcontract
sort
publicstatic void sort(T[] a,
int fromIndex,
int toIndex,
Comparator c)
Sortsthespecifiedrangeofthespecifiedarrayofobjectsaccording
totheorderinducedbythespecifiedcomparator.Therangetobe
sortedextendsfromindexfromIndex,inclusive,toindex
toIndex,exclusive.(IffromIndex==toIndex,the
rangetobesortedisempty.)Allelementsintherangemustbe
mutuallycomparablebythespecifiedcomparator(thatis,
c.compare(e1,e2)mustnotthrowaClassCastException
foranyelementse1ande2intherange).
Thissortisguaranteedtobestable:equalelementswill
notbereorderedasaresultofthesort.
Implementationnote:Thisimplementationisastable,adaptive,
iterativemergesortthatrequiresfarfewerthannlg(n)comparisons
whentheinputarrayispartiallysorted,whileofferingthe
performanceofatraditionalmergesortwhentheinputarrayis
randomlyordered.Iftheinputarrayisnearlysorted,the
implementationrequiresapproximatelyncomparisons.Temporary
storagerequirementsvaryfromasmallconstantfornearlysorted
inputarrayston/2objectreferencesforrandomlyorderedinput
arrays.
Theimplementationtakesequaladvantageofascendingand
descendingorderinitsinputarray,andcantakeadvantageof
ascendinganddescendingorderindifferentpartsofthethesame
inputarray.Itiswell-suitedtomergingtwoormoresortedarrays:
simplyconcatenatethearraysandsorttheresultingarray.
TheimplementationwasadaptedfromTimPeters'slistsortforPython
(
TimSort).ItusestechiquesfromPeterMcIlroy's"Optimistic
SortingandInformationTheoreticComplexity",inProceedingsofthe
FourthAnnualACM-SIAMSymposiumonDiscreteAlgorithms,pp467-474,
January1993.
Parameters:a-thearraytobesortedfromIndex-theindexofthefirstelement(inclusive)tobe
sortedtoIndex-theindexofthelastelement(exclusive)tobesortedc-thecomparatortodeterminetheorderofthearray.A
nullvalueindicatesthattheelements'
naturalorderingshouldbeused.
Throws:
ClassCastException-ifthearraycontainselementsthatarenot
mutuallycomparableusingthespecifiedcomparator.
IllegalArgumentException-iffromIndex>toIndexor
(optional)ifthecomparatorisfoundtoviolatethe
Comparatorcontract
ArrayIndexOutOfBoundsException-iffromIndex<0or
toIndex>a.length
binarySearch
publicstatic int binarySearch(long[] a,
long key)
Searchesthespecifiedarrayoflongsforthespecifiedvalueusingthe
binarysearchalgorithm.Thearraymustbesorted(as
bythesort(long[])method)priortomakingthiscall.Ifit
isnotsorted,theresultsareundefined.Ifthearraycontains
multipleelementswiththespecifiedvalue,thereisnoguaranteewhich
onewillbefound.
Parameters:a-thearraytobesearchedkey-thevaluetobesearchedfor
Returns:indexofthesearchkey,ifitiscontainedinthearray;
otherwise,(-(insertionpoint)-1).The
insertionpointisdefinedasthepointatwhichthe
keywouldbeinsertedintothearray:theindexofthefirst
elementgreaterthanthekey,ora.lengthifall
elementsinthearrayarelessthanthespecifiedkey.Note
thatthisguaranteesthatthereturnvaluewillbe>=0if
andonlyifthekeyisfound.
binarySearch
publicstatic int binarySearch(long[] a,
int fromIndex,
int toIndex,
long key)
Searchesarangeof
thespecifiedarrayoflongsforthespecifiedvalueusingthe
binarysearchalgorithm.
Therangemustbesorted(as
bythesort(long[],int,int)method)
priortomakingthiscall.Ifit
isnotsorted,theresultsareundefined.Iftherangecontains
multipleelementswiththespecifiedvalue,thereisnoguaranteewhich
onewillbefound.
Parameters:a-thearraytobesearchedfromIndex-theindexofthefirstelement(inclusive)tobe
searchedtoIndex-theindexofthelastelement(exclusive)tobesearchedkey-thevaluetobesearchedfor
Returns:indexofthesearchkey,ifitiscontainedinthearray
withinthespecifiedrange;
otherwise,(-(insertionpoint)-1).The
insertionpointisdefinedasthepointatwhichthe
keywouldbeinsertedintothearray:theindexofthefirst
elementintherangegreaterthanthekey,
ortoIndexifall
elementsintherangearelessthanthespecifiedkey.Note
thatthisguaranteesthatthereturnvaluewillbe>=0if
andonlyifthekeyisfound.
Throws:
IllegalArgumentException-iffromIndex>toIndex
ArrayIndexOutOfBoundsException-iffromIndex<0ortoIndex>a.lengthSince:
1.6
binarySearch
publicstatic int binarySearch(int[] a,
int key)
Searchesthespecifiedarrayofintsforthespecifiedvalueusingthe
binarysearchalgorithm.Thearraymustbesorted(as
bythesort(int[])method)priortomakingthiscall.Ifit
isnotsorted,theresultsareundefined.Ifthearraycontains
multipleelementswiththespecifiedvalue,thereisnoguaranteewhich
onewillbefound.
Parameters:a-thearraytobesearchedkey-thevaluetobesearchedfor
Returns:indexofthesearchkey,ifitiscontainedinthearray;
otherwise,(-(insertionpoint)-1).The
insertionpointisdefinedasthepointatwhichthe
keywouldbeinsertedintothearray:theindexofthefirst
elementgreaterthanthekey,ora.lengthifall
elementsinthearrayarelessthanthespecifiedkey.Note
thatthisguaranteesthatthereturnvaluewillbe>=0if
andonlyifthekeyisfound.
binarySearch
publicstatic int binarySearch(int[] a,
int fromIndex,
int toIndex,
int key)
Searchesarangeof
thespecifiedarrayofintsforthespecifiedvalueusingthe
binarysearchalgorithm.
Therangemustbesorted(as
bythesort(int[],int,int)method)
priortomakingthiscall.Ifit
isnotsorted,theresultsareundefined.Iftherangecontains
multipleelementswiththespecifiedvalue,thereisnoguaranteewhich
onewillbefound.
Parameters:a-thearraytobesearchedfromIndex-theindexofthefirstelement(inclusive)tobe
searchedtoIndex-theindexofthelastelement(exclusive)tobesearchedkey-thevaluetobesearchedfor
Returns:indexofthesearchkey,ifitiscontainedinthearray
withinthespecifiedrange;
otherwise,(-(insertionpoint)-1).The
insertionpointisdefinedasthepointatwhichthe
keywouldbeinsertedintothearray:theindexofthefirst
elementintherangegreaterthanthekey,
ortoIndexifall
elementsintherangearelessthanthespecifiedkey.Note
thatthisguaranteesthatthereturnvaluewillbe>=0if
andonlyifthekeyisfound.
Throws:
IllegalArgumentException-iffromIndex>toIndex
ArrayIndexOutOfBoundsException-iffromIndex<0ortoIndex>a.lengthSince:
1.6
binarySearch
publicstatic int binarySearch(short[] a,
short key)
Searchesthespecifiedarrayofshortsforthespecifiedvalueusing
thebinarysearchalgorithm.Thearraymustbesorted
(asbythesort(short[])method)priortomakingthiscall.If
itisnotsorted,theresultsareundefined.Ifthearraycontains
multipleelementswiththespecifiedvalue,thereisnoguaranteewhich
onewillbefound.
Parameters:a-thearraytobesearchedkey-thevaluetobesearchedfor
Returns:indexofthesearchkey,ifitiscontainedinthearray;
otherwise,(-(insertionpoint)-1).The
insertionpointisdefinedasthepointatwhichthe
keywouldbeinsertedintothearray:theindexofthefirst
elementgreaterthanthekey,ora.lengthifall
elementsinthearrayarelessthanthespecifiedkey.Note
thatthisguaranteesthatthereturnvaluewillbe>=0if
andonlyifthekeyisfound.
binarySearch
publicstatic int binarySearch(short[] a,
int fromIndex,
int toIndex,
short key)
Searchesarangeof
thespecifiedarrayofshortsforthespecifiedvalueusing
thebinarysearchalgorithm.
Therangemustbesorted
(asbythesort(short[],int,int)method)
priortomakingthiscall.If
itisnotsorted,theresultsareundefined.Iftherangecontains
multipleelementswiththespecifiedvalue,thereisnoguaranteewhich
onewillbefound.
Parameters:a-thearraytobesearchedfromIndex-theindexofthefirstelement(inclusive)tobe
searchedtoIndex-theindexofthelastelement(exclusive)tobesearchedkey-thevaluetobesearchedfor
Returns:indexofthesearchkey,ifitiscontainedinthearray
withinthespecifiedrange;
otherwise,(-(insertionpoint)-1).The
insertionpointisdefinedasthepointatwhichthe
keywouldbeinsertedintothearray:theindexofthefirst
elementintherangegreaterthanthekey,
ortoIndexifall
elementsintherangearelessthanthespecifiedkey.Note
thatthisguaranteesthatthereturnvaluewillbe>=0if
andonlyifthekeyisfound.
Throws:
IllegalArgumentException-iffromIndex>toIndex
ArrayIndexOutOfBoundsException-iffromIndex<0ortoIndex>a.lengthSince:
1.6
binarySearch
publicstatic int binarySearch(char[] a,
char key)
Searchesthespecifiedarrayofcharsforthespecifiedvalueusingthe
binarysearchalgorithm.Thearraymustbesorted(as
bythesort(char[])method)priortomakingthiscall.Ifit
isnotsorted,theresultsareundefined.Ifthearraycontains
multipleelementswiththespecifiedvalue,thereisnoguaranteewhich
onewillbefound.
Parameters:a-thearraytobesearchedkey-thevaluetobesearchedfor
Returns:indexofthesearchkey,ifitiscontainedinthearray;
otherwise,(-(insertionpoint)-1).The
insertionpointisdefinedasthepointatwhichthe
keywouldbeinsertedintothearray:theindexofthefirst
elementgreaterthanthekey,ora.lengthifall
elementsinthearrayarelessthanthespecifiedkey.Note
thatthisguaranteesthatthereturnvaluewillbe>=0if
andonlyifthekeyisfound.
binarySearch
publicstatic int binarySearch(char[] a,
int fromIndex,
int toIndex,
char key)
Searchesarangeof
thespecifiedarrayofcharsforthespecifiedvalueusingthe
binarysearchalgorithm.
Therangemustbesorted(as
bythesort(char[],int,int)method)
priortomakingthiscall.Ifit
isnotsorted,theresultsareundefined.Iftherangecontains
multipleelementswiththespecifiedvalue,thereisnoguaranteewhich
onewillbefound.
Parameters:a-thearraytobesearchedfromIndex-theindexofthefirstelement(inclusive)tobe
searchedtoIndex-theindexofthelastelement(exclusive)tobesearchedkey-thevaluetobesearchedfor
Returns:indexofthesearchkey,ifitiscontainedinthearray
withinthespecifiedrange;
otherwise,(-(insertionpoint)-1).The
insertionpointisdefinedasthepointatwhichthe
keywouldbeinsertedintothearray:theindexofthefirst
elementintherangegreaterthanthekey,
ortoIndexifall
elementsintherangearelessthanthespecifiedkey.Note
thatthisguaranteesthatthereturnvaluewillbe>=0if
andonlyifthekeyisfound.
Throws:
IllegalArgumentException-iffromIndex>toIndex
ArrayIndexOutOfBoundsException-iffromIndex<0ortoIndex>a.lengthSince:
1.6
binarySearch
publicstatic int binarySearch(byte[] a,
byte key)
Searchesthespecifiedarrayofbytesforthespecifiedvalueusingthe
binarysearchalgorithm.Thearraymustbesorted(as
bythesort(byte[])method)priortomakingthiscall.Ifit
isnotsorted,theresultsareundefined.Ifthearraycontains
multipleelementswiththespecifiedvalue,thereisnoguaranteewhich
onewillbefound.
Parameters:a-thearraytobesearchedkey-thevaluetobesearchedfor
Returns:indexofthesearchkey,ifitiscontainedinthearray;
otherwise,(-(insertionpoint)-1).The
insertionpointisdefinedasthepointatwhichthe
keywouldbeinsertedintothearray:theindexofthefirst
elementgreaterthanthekey,ora.lengthifall
elementsinthearrayarelessthanthespecifiedkey.Note
thatthisguaranteesthatthereturnvaluewillbe>=0if
andonlyifthekeyisfound.
binarySearch
publicstatic int binarySearch(byte[] a,
int fromIndex,
int toIndex,
byte key)
Searchesarangeof
thespecifiedarrayofbytesforthespecifiedvalueusingthe
binarysearchalgorithm.
Therangemustbesorted(as
bythesort(byte[],int,int)method)
priortomakingthiscall.Ifit
isnotsorted,theresultsareundefined.Iftherangecontains
multipleelementswiththespecifiedvalue,thereisnoguaranteewhich
onewillbefound.
Parameters:a-thearraytobesearchedfromIndex-theindexofthefirstelement(inclusive)tobe
searchedtoIndex-theindexofthelastelement(exclusive)tobesearchedkey-thevaluetobesearchedfor
Returns:indexofthesearchkey,ifitiscontainedinthearray
withinthespecifiedrange;
otherwise,(-(insertionpoint)-1).The
insertionpointisdefinedasthepointatwhichthe
keywouldbeinsertedintothearray:theindexofthefirst
elementintherangegreaterthanthekey,
ortoIndexifall
elementsintherangearelessthanthespecifiedkey.Note
thatthisguaranteesthatthereturnvaluewillbe>=0if
andonlyifthekeyisfound.
Throws:
IllegalArgumentException-iffromIndex>toIndex
ArrayIndexOutOfBoundsException-iffromIndex<0ortoIndex>a.lengthSince:
1.6
binarySearch
publicstatic int binarySearch(double[] a,
double key)
Searchesthespecifiedarrayofdoublesforthespecifiedvalueusing
thebinarysearchalgorithm.Thearraymustbesorted
(asbythesort(double[])method)priortomakingthiscall.
Ifitisnotsorted,theresultsareundefined.Ifthearraycontains
multipleelementswiththespecifiedvalue,thereisnoguaranteewhich
onewillbefound.ThismethodconsidersallNaNvaluestobe
equivalentandequal.
Parameters:a-thearraytobesearchedkey-thevaluetobesearchedfor
Returns:indexofthesearchkey,ifitiscontainedinthearray;
otherwise,(-(insertionpoint)-1).The
insertionpointisdefinedasthepointatwhichthe
keywouldbeinsertedintothearray:theindexofthefirst
elementgreaterthanthekey,ora.lengthifall
elementsinthearrayarelessthanthespecifiedkey.Note
thatthisguaranteesthatthereturnvaluewillbe>=0if
andonlyifthekeyisfound.
binarySearch
publicstatic int binarySearch(double[] a,
int fromIndex,
int toIndex,
double key)
Searchesarangeof
thespecifiedarrayofdoublesforthespecifiedvalueusing
thebinarysearchalgorithm.
Therangemustbesorted
(asbythesort(double[],int,int)method)
priortomakingthiscall.
Ifitisnotsorted,theresultsareundefined.Iftherangecontains
multipleelementswiththespecifiedvalue,thereisnoguaranteewhich
onewillbefound.ThismethodconsidersallNaNvaluestobe
equivalentandequal.
Parameters:a-thearraytobesearchedfromIndex-theindexofthefirstelement(inclusive)tobe
searchedtoIndex-theindexofthelastelement(exclusive)tobesearchedkey-thevaluetobesearchedfor
Returns:indexofthesearchkey,ifitiscontainedinthearray
withinthespecifiedrange;
otherwise,(-(insertionpoint)-1).The
insertionpointisdefinedasthepointatwhichthe
keywouldbeinsertedintothearray:theindexofthefirst
elementintherangegreaterthanthekey,
ortoIndexifall
elementsintherangearelessthanthespecifiedkey.Note
thatthisguaranteesthatthereturnvaluewillbe>=0if
andonlyifthekeyisfound.
Throws:
IllegalArgumentException-iffromIndex>toIndex
ArrayIndexOutOfBoundsException-iffromIndex<0ortoIndex>a.lengthSince:
1.6
binarySearch
publicstatic int binarySearch(float[] a,
float key)
Searchesthespecifiedarrayoffloatsforthespecifiedvalueusing
thebinarysearchalgorithm.Thearraymustbesorted
(asbythesort(float[])method)priortomakingthiscall.If
itisnotsorted,theresultsareundefined.Ifthearraycontains
multipleelementswiththespecifiedvalue,thereisnoguaranteewhich
onewillbefound.ThismethodconsidersallNaNvaluestobe
equivalentandequal.
Parameters:a-thearraytobesearchedkey-thevaluetobesearchedfor
Returns:indexofthesearchkey,ifitiscontainedinthearray;
otherwise,(-(insertionpoint)-1).The
insertionpointisdefinedasthepointatwhichthe
keywouldbeinsertedintothearray:theindexofthefirst
elementgreaterthanthekey,ora.lengthifall
elementsinthearrayarelessthanthespecifiedkey.Note
thatthisguaranteesthatthereturnvaluewillbe>=0if
andonlyifthekeyisfound.
binarySearch
publicstatic int binarySearch(float[] a,
int fromIndex,
int toIndex,
float key)
Searchesarangeof
thespecifiedarrayoffloatsforthespecifiedvalueusing
thebinarysearchalgorithm.
Therangemustbesorted
(asbythesort(float[],int,int)method)
priortomakingthiscall.If
itisnotsorted,theresultsareundefined.Iftherangecontains
multipleelementswiththespecifiedvalue,thereisnoguaranteewhich
onewillbefound.ThismethodconsidersallNaNvaluestobe
equivalentandequal.
Parameters:a-thearraytobesearchedfromIndex-theindexofthefirstelement(inclusive)tobe
searchedtoIndex-theindexofthelastelement(exclusive)tobesearchedkey-thevaluetobesearchedfor
Returns:indexofthesearchkey,ifitiscontainedinthearray
withinthespecifiedrange;
otherwise,(-(insertionpoint)-1).The
insertionpointisdefinedasthepointatwhichthe
keywouldbeinsertedintothearray:theindexofthefirst
elementintherangegreaterthanthekey,
ortoIndexifall
elementsintherangearelessthanthespecifiedkey.Note
thatthisguaranteesthatthereturnvaluewillbe>=0if
andonlyifthekeyisfound.
Throws:
IllegalArgumentException-iffromIndex>toIndex
ArrayIndexOutOfBoundsException-iffromIndex<0ortoIndex>a.lengthSince:
1.6
binarySearch
publicstatic int binarySearch(Object[] a,
Object key)
Searchesthespecifiedarrayforthespecifiedobjectusingthebinary
searchalgorithm.Thearraymustbesortedintoascendingorder
accordingtothe
naturalordering
ofitselements(asbythe
sort(Object[])method)priortomakingthiscall.
Ifitisnotsorted,theresultsareundefined.
(Ifthearraycontainselementsthatarenotmutuallycomparable(for
example,stringsandintegers),itcannotbesortedaccording
tothenaturalorderingofitselements,henceresultsareundefined.)
Ifthearraycontainsmultiple
elementsequaltothespecifiedobject,thereisnoguaranteewhich
onewillbefound.
Parameters:a-thearraytobesearchedkey-thevaluetobesearchedfor
Returns:indexofthesearchkey,ifitiscontainedinthearray;
otherwise,(-(insertionpoint)-1).The
insertionpointisdefinedasthepointatwhichthe
keywouldbeinsertedintothearray:theindexofthefirst
elementgreaterthanthekey,ora.lengthifall
elementsinthearrayarelessthanthespecifiedkey.Note
thatthisguaranteesthatthereturnvaluewillbe>=0if
andonlyifthekeyisfound.
Throws:
ClassCastException-ifthesearchkeyisnotcomparabletothe
elementsofthearray.
binarySearch
publicstatic int binarySearch(Object[] a,
int fromIndex,
int toIndex,
Object key)
Searchesarangeof
thespecifiedarrayforthespecifiedobjectusingthebinary
searchalgorithm.
Therangemustbesortedintoascendingorder
accordingtothe
naturalordering
ofitselements(asbythe
sort(Object[],int,int)method)priortomakingthis
call.Ifitisnotsorted,theresultsareundefined.
(Iftherangecontainselementsthatarenotmutuallycomparable(for
example,stringsandintegers),itcannotbesortedaccording
tothenaturalorderingofitselements,henceresultsareundefined.)
Iftherangecontainsmultiple
elementsequaltothespecifiedobject,thereisnoguaranteewhich
onewillbefound.
Parameters:a-thearraytobesearchedfromIndex-theindexofthefirstelement(inclusive)tobe
searchedtoIndex-theindexofthelastelement(exclusive)tobesearchedkey-thevaluetobesearchedfor
Returns:indexofthesearchkey,ifitiscontainedinthearray
withinthespecifiedrange;
otherwise,(-(insertionpoint)-1).The
insertionpointisdefinedasthepointatwhichthe
keywouldbeinsertedintothearray:theindexofthefirst
elementintherangegreaterthanthekey,
ortoIndexifall
elementsintherangearelessthanthespecifiedkey.Note
thatthisguaranteesthatthereturnvaluewillbe>=0if
andonlyifthekeyisfound.
Throws:
ClassCastException-ifthesearchkeyisnotcomparabletothe
elementsofthearraywithinthespecifiedrange.
IllegalArgumentException-iffromIndex>toIndex
ArrayIndexOutOfBoundsException-iffromIndex<0ortoIndex>a.lengthSince:
1.6
binarySearch
publicstatic int binarySearch(T[] a,
T key,
Comparator c)
Searchesthespecifiedarrayforthespecifiedobjectusingthebinary
searchalgorithm.Thearraymustbesortedintoascendingorder
accordingtothespecifiedcomparator(asbythe
sort(T[],Comparator)
method)priortomakingthiscall.Ifitis
notsorted,theresultsareundefined.
Ifthearraycontainsmultiple
elementsequaltothespecifiedobject,thereisnoguaranteewhichone
willbefound.
Parameters:a-thearraytobesearchedkey-thevaluetobesearchedforc-thecomparatorbywhichthearrayisordered.A
nullvalueindicatesthattheelements'
naturalorderingshouldbeused.
Returns:indexofthesearchkey,ifitiscontainedinthearray;
otherwise,(-(insertionpoint)-1).The
insertionpointisdefinedasthepointatwhichthe
keywouldbeinsertedintothearray:theindexofthefirst
elementgreaterthanthekey,ora.lengthifall
elementsinthearrayarelessthanthespecifiedkey.Note
thatthisguaranteesthatthereturnvaluewillbe>=0if
andonlyifthekeyisfound.
Throws:
ClassCastException-ifthearraycontainselementsthatarenot
mutuallycomparableusingthespecifiedcomparator,
orthesearchkeyisnotcomparabletothe
elementsofthearrayusingthiscomparator.
binarySearch
publicstatic int binarySearch(T[] a,
int fromIndex,
int toIndex,
T key,
Comparator c)
Searchesarangeof
thespecifiedarrayforthespecifiedobjectusingthebinary
searchalgorithm.
Therangemustbesortedintoascendingorder
accordingtothespecifiedcomparator(asbythe
sort(T[],int,int,Comparator)
method)priortomakingthiscall.
Ifitisnotsorted,theresultsareundefined.
Iftherangecontainsmultipleelementsequaltothespecifiedobject,
thereisnoguaranteewhichonewillbefound.
Parameters:a-thearraytobesearchedfromIndex-theindexofthefirstelement(inclusive)tobe
searchedtoIndex-theindexofthelastelement(exclusive)tobesearchedkey-thevaluetobesearchedforc-thecomparatorbywhichthearrayisordered.A
nullvalueindicatesthattheelements'
naturalorderingshouldbeused.
Returns:indexofthesearchkey,ifitiscontainedinthearray
withinthespecifiedrange;
otherwise,(-(insertionpoint)-1).The
insertionpointisdefinedasthepointatwhichthe
keywouldbeinsertedintothearray:theindexofthefirst
elementintherangegreaterthanthekey,
ortoIndexifall
elementsintherangearelessthanthespecifiedkey.Note
thatthisguaranteesthatthereturnvaluewillbe>=0if
andonlyifthekeyisfound.
Throws:
ClassCastException-iftherangecontainselementsthatarenot
mutuallycomparableusingthespecifiedcomparator,
orthesearchkeyisnotcomparabletothe
elementsintherangeusingthiscomparator.
IllegalArgumentException-iffromIndex>toIndex
ArrayIndexOutOfBoundsException-iffromIndex<0ortoIndex>a.lengthSince:
1.6
equals
publicstatic boolean equals(long[] a,
long[] a2)
Returnstrueifthetwospecifiedarraysoflongsare
equaltooneanother.Twoarraysareconsideredequalifboth
arrayscontainthesamenumberofelements,andallcorrespondingpairs
ofelementsinthetwoarraysareequal.Inotherwords,twoarrays
areequaliftheycontainthesameelementsinthesameorder.Also,
twoarrayreferencesareconsideredequalifbotharenull.
Parameters:a-onearraytobetestedforequalitya2-theotherarraytobetestedforequality
Returns:trueifthetwoarraysareequal
equals
publicstatic boolean equals(int[] a,
int[] a2)
Returnstrueifthetwospecifiedarraysofintsare
equaltooneanother.Twoarraysareconsideredequalifboth
arrayscontainthesamenumberofelements,andallcorrespondingpairs
ofelementsinthetwoarraysareequal.Inotherwords,twoarrays
areequaliftheycontainthesameelementsinthesameorder.Also,
twoarrayreferencesareconsideredequalifbotharenull.
Parameters:a-onearraytobetestedforequalitya2-theotherarraytobetestedforequality
Returns:trueifthetwoarraysareequal
equals
publicstatic boolean equals(short[] a,
short[] a2)
Returnstrueifthetwospecifiedarraysofshortsare
equaltooneanother.Twoarraysareconsideredequalifboth
arrayscontainthesamenumberofelements,andallcorrespondingpairs
ofelementsinthetwoarraysareequal.Inotherwords,twoarrays
areequaliftheycontainthesameelementsinthesameorder.Also,
twoarrayreferencesareconsideredequalifbotharenull.
Parameters:a-onearraytobetestedforequalitya2-theotherarraytobetestedforequality
Returns:trueifthetwoarraysareequal
equals
publicstatic boolean equals(char[] a,
char[] a2)
Returnstrueifthetwospecifiedarraysofcharsare
equaltooneanother.Twoarraysareconsideredequalifboth
arrayscontainthesamenumberofelements,andallcorrespondingpairs
ofelementsinthetwoarraysareequal.Inotherwords,twoarrays
areequaliftheycontainthesameelementsinthesameorder.Also,
twoarrayreferencesareconsideredequalifbotharenull.
Parameters:a-onearraytobetestedforequalitya2-theotherarraytobetestedforequality
Returns:trueifthetwoarraysareequal
equals
publicstatic boolean equals(byte[] a,
byte[] a2)
Returnstrueifthetwospecifiedarraysofbytesare
equaltooneanother.Twoarraysareconsideredequalifboth
arrayscontainthesamenumberofelements,andallcorrespondingpairs
ofelementsinthetwoarraysareequal.Inotherwords,twoarrays
areequaliftheycontainthesameelementsinthesameorder.Also,
twoarrayreferencesareconsideredequalifbotharenull.
Parameters:a-onearraytobetestedforequalitya2-theotherarraytobetestedforequality
Returns:trueifthetwoarraysareequal
equals
publicstatic boolean equals(boolean[] a,
boolean[] a2)
Returnstrueifthetwospecifiedarraysofbooleansare
equaltooneanother.Twoarraysareconsideredequalifboth
arrayscontainthesamenumberofelements,andallcorrespondingpairs
ofelementsinthetwoarraysareequal.Inotherwords,twoarrays
areequaliftheycontainthesameelementsinthesameorder.Also,
twoarrayreferencesareconsideredequalifbotharenull.
Parameters:a-onearraytobetestedforequalitya2-theotherarraytobetestedforequality
Returns:trueifthetwoarraysareequal
equals
publicstatic boolean equals(double[] a,
double[] a2)
Returnstrueifthetwospecifiedarraysofdoublesare
equaltooneanother.Twoarraysareconsideredequalifboth
arrayscontainthesamenumberofelements,andallcorrespondingpairs
ofelementsinthetwoarraysareequal.Inotherwords,twoarrays
areequaliftheycontainthesameelementsinthesameorder.Also,
twoarrayreferencesareconsideredequalifbotharenull.
Twodoublesd1andd2areconsideredequalif:
newDouble(d1).equals(newDouble(d2))
(Unlikethe==operator,thismethodconsiders
NaNequalstoitself,and0.0dunequalto-0.0d.)
Parameters:a-onearraytobetestedforequalitya2-theotherarraytobetestedforequality
Returns:trueifthetwoarraysareequalSeeAlso:Double.equals(Object)
equals
publicstatic boolean equals(float[] a,
float[] a2)
Returnstrueifthetwospecifiedarraysoffloatsare
equaltooneanother.Twoarraysareconsideredequalifboth
arrayscontainthesamenumberofelements,andallcorrespondingpairs
ofelementsinthetwoarraysareequal.Inotherwords,twoarrays
areequaliftheycontainthesameelementsinthesameorder.Also,
twoarrayreferencesareconsideredequalifbotharenull.
Twofloatsf1andf2areconsideredequalif:
newFloat(f1).equals(newFloat(f2))
(Unlikethe==operator,thismethodconsiders
NaNequalstoitself,and0.0funequalto-0.0f.)
Parameters:a-onearraytobetestedforequalitya2-theotherarraytobetestedforequality
Returns:trueifthetwoarraysareequalSeeAlso:Float.equals(Object)
equals
publicstatic boolean equals(Object[] a,
Object[] a2)
ReturnstrueifthetwospecifiedarraysofObjectsare
equaltooneanother.Thetwoarraysareconsideredequalif
botharrayscontainthesamenumberofelements,andallcorresponding
pairsofelementsinthetwoarraysareequal.Twoobjectse1
ande2areconsideredequalif(e1==null?e2==null
:e1.equals(e2)).Inotherwords,thetwoarraysareequalif
theycontainthesameelementsinthesameorder.Also,twoarray
referencesareconsideredequalifbotharenull.
Parameters:a-onearraytobetestedforequalitya2-theotherarraytobetestedforequality
Returns:trueifthetwoarraysareequal
fill
publicstatic void fill(long[] a,
long val)
Assignsthespecifiedlongvaluetoeachelementofthespecifiedarray
oflongs.
Parameters:a-thearraytobefilledval-thevaluetobestoredinallelementsofthearray
fill
publicstatic void fill(long[] a,
int fromIndex,
int toIndex,
long val)
Assignsthespecifiedlongvaluetoeachelementofthespecified
rangeofthespecifiedarrayoflongs.Therangetobefilled
extendsfromindexfromIndex,inclusive,toindex
toIndex,exclusive.(IffromIndex==toIndex,the
rangetobefilledisempty.)
Parameters:a-thearraytobefilledfromIndex-theindexofthefirstelement(inclusive)tobe
filledwiththespecifiedvaluetoIndex-theindexofthelastelement(exclusive)tobe
filledwiththespecifiedvalueval-thevaluetobestoredinallelementsofthearray
Throws:
IllegalArgumentException-iffromIndex>toIndex
ArrayIndexOutOfBoundsException-iffromIndex<0or
toIndex>a.length
fill
publicstatic void fill(int[] a,
int val)
Assignsthespecifiedintvaluetoeachelementofthespecifiedarray
ofints.
Parameters:a-thearraytobefilledval-thevaluetobestoredinallelementsofthearray
fill
publicstatic void fill(int[] a,
int fromIndex,
int toIndex,
int val)
Assignsthespecifiedintvaluetoeachelementofthespecified
rangeofthespecifiedarrayofints.Therangetobefilled
extendsfromindexfromIndex,inclusive,toindex
toIndex,exclusive.(IffromIndex==toIndex,the
rangetobefilledisempty.)
Parameters:a-thearraytobefilledfromIndex-theindexofthefirstelement(inclusive)tobe
filledwiththespecifiedvaluetoIndex-theindexofthelastelement(exclusive)tobe
filledwiththespecifiedvalueval-thevaluetobestoredinallelementsofthearray
Throws:
IllegalArgumentException-iffromIndex>toIndex
ArrayIndexOutOfBoundsException-iffromIndex<0or
toIndex>a.length
fill
publicstatic void fill(short[] a,
short val)
Assignsthespecifiedshortvaluetoeachelementofthespecifiedarray
ofshorts.
Parameters:a-thearraytobefilledval-thevaluetobestoredinallelementsofthearray
fill
publicstatic void fill(short[] a,
int fromIndex,
int toIndex,
short val)
Assignsthespecifiedshortvaluetoeachelementofthespecified
rangeofthespecifiedarrayofshorts.Therangetobefilled
extendsfromindexfromIndex,inclusive,toindex
toIndex,exclusive.(IffromIndex==toIndex,the
rangetobefilledisempty.)
Parameters:a-thearraytobefilledfromIndex-theindexofthefirstelement(inclusive)tobe
filledwiththespecifiedvaluetoIndex-theindexofthelastelement(exclusive)tobe
filledwiththespecifiedvalueval-thevaluetobestoredinallelementsofthearray
Throws:
IllegalArgumentException-iffromIndex>toIndex
ArrayIndexOutOfBoundsException-iffromIndex<0or
toIndex>a.length
fill
publicstatic void fill(char[] a,
char val)
Assignsthespecifiedcharvaluetoeachelementofthespecifiedarray
ofchars.
Parameters:a-thearraytobefilledval-thevaluetobestoredinallelementsofthearray
fill
publicstatic void fill(char[] a,
int fromIndex,
int toIndex,
char val)
Assignsthespecifiedcharvaluetoeachelementofthespecified
rangeofthespecifiedarrayofchars.Therangetobefilled
extendsfromindexfromIndex,inclusive,toindex
toIndex,exclusive.(IffromIndex==toIndex,the
rangetobefilledisempty.)
Parameters:a-thearraytobefilledfromIndex-theindexofthefirstelement(inclusive)tobe
filledwiththespecifiedvaluetoIndex-theindexofthelastelement(exclusive)tobe
filledwiththespecifiedvalueval-thevaluetobestoredinallelementsofthearray
Throws:
IllegalArgumentException-iffromIndex>toIndex
ArrayIndexOutOfBoundsException-iffromIndex<0or
toIndex>a.length
fill
publicstatic void fill(byte[] a,
byte val)
Assignsthespecifiedbytevaluetoeachelementofthespecifiedarray
ofbytes.
Parameters:a-thearraytobefilledval-thevaluetobestoredinallelementsofthearray
fill
publicstatic void fill(byte[] a,
int fromIndex,
int toIndex,
byte val)
Assignsthespecifiedbytevaluetoeachelementofthespecified
rangeofthespecifiedarrayofbytes.Therangetobefilled
extendsfromindexfromIndex,inclusive,toindex
toIndex,exclusive.(IffromIndex==toIndex,the
rangetobefilledisempty.)
Parameters:a-thearraytobefilledfromIndex-theindexofthefirstelement(inclusive)tobe
filledwiththespecifiedvaluetoIndex-theindexofthelastelement(exclusive)tobe
filledwiththespecifiedvalueval-thevaluetobestoredinallelementsofthearray
Throws:
IllegalArgumentException-iffromIndex>toIndex
ArrayIndexOutOfBoundsException-iffromIndex<0or
toIndex>a.length
fill
publicstatic void fill(boolean[] a,
boolean val)
Assignsthespecifiedbooleanvaluetoeachelementofthespecified
arrayofbooleans.
Parameters:a-thearraytobefilledval-thevaluetobestoredinallelementsofthearray
fill
publicstatic void fill(boolean[] a,
int fromIndex,
int toIndex,
boolean val)
Assignsthespecifiedbooleanvaluetoeachelementofthespecified
rangeofthespecifiedarrayofbooleans.Therangetobefilled
extendsfromindexfromIndex,inclusive,toindex
toIndex,exclusive.(IffromIndex==toIndex,the
rangetobefilledisempty.)
Parameters:a-thearraytobefilledfromIndex-theindexofthefirstelement(inclusive)tobe
filledwiththespecifiedvaluetoIndex-theindexofthelastelement(exclusive)tobe
filledwiththespecifiedvalueval-thevaluetobestoredinallelementsofthearray
Throws:
IllegalArgumentException-iffromIndex>toIndex
ArrayIndexOutOfBoundsException-iffromIndex<0or
toIndex>a.length
fill
publicstatic void fill(double[] a,
double val)
Assignsthespecifieddoublevaluetoeachelementofthespecified
arrayofdoubles.
Parameters:a-thearraytobefilledval-thevaluetobestoredinallelementsofthearray
fill
publicstatic void fill(double[] a,
int fromIndex,
int toIndex,
double val)
Assignsthespecifieddoublevaluetoeachelementofthespecified
rangeofthespecifiedarrayofdoubles.Therangetobefilled
extendsfromindexfromIndex,inclusive,toindex
toIndex,exclusive.(IffromIndex==toIndex,the
rangetobefilledisempty.)
Parameters:a-thearraytobefilledfromIndex-theindexofthefirstelement(inclusive)tobe
filledwiththespecifiedvaluetoIndex-theindexofthelastelement(exclusive)tobe
filledwiththespecifiedvalueval-thevaluetobestoredinallelementsofthearray
Throws:
IllegalArgumentException-iffromIndex>toIndex
ArrayIndexOutOfBoundsException-iffromIndex<0or
toIndex>a.length
fill
publicstatic void fill(float[] a,
float val)
Assignsthespecifiedfloatvaluetoeachelementofthespecifiedarray
offloats.
Parameters:a-thearraytobefilledval-thevaluetobestoredinallelementsofthearray
fill
publicstatic void fill(float[] a,
int fromIndex,
int toIndex,
float val)
Assignsthespecifiedfloatvaluetoeachelementofthespecified
rangeofthespecifiedarrayoffloats.Therangetobefilled
extendsfromindexfromIndex,inclusive,toindex
toIndex,exclusive.(IffromIndex==toIndex,the
rangetobefilledisempty.)
Parameters:a-thearraytobefilledfromIndex-theindexofthefirstelement(inclusive)tobe
filledwiththespecifiedvaluetoIndex-theindexofthelastelement(exclusive)tobe
filledwiththespecifiedvalueval-thevaluetobestoredinallelementsofthearray
Throws:
IllegalArgumentException-iffromIndex>toIndex
ArrayIndexOutOfBoundsException-iffromIndex<0or
toIndex>a.length
fill
publicstatic void fill(Object[] a,
Object val)
AssignsthespecifiedObjectreferencetoeachelementofthespecified
arrayofObjects.
Parameters:a-thearraytobefilledval-thevaluetobestoredinallelementsofthearray
Throws:
ArrayStoreException-ifthespecifiedvalueisnotofa
runtimetypethatcanbestoredinthespecifiedarray
fill
publicstatic void fill(Object[] a,
int fromIndex,
int toIndex,
Object val)
AssignsthespecifiedObjectreferencetoeachelementofthespecified
rangeofthespecifiedarrayofObjects.Therangetobefilled
extendsfromindexfromIndex,inclusive,toindex
toIndex,exclusive.(IffromIndex==toIndex,the
rangetobefilledisempty.)
Parameters:a-thearraytobefilledfromIndex-theindexofthefirstelement(inclusive)tobe
filledwiththespecifiedvaluetoIndex-theindexofthelastelement(exclusive)tobe
filledwiththespecifiedvalueval-thevaluetobestoredinallelementsofthearray
Throws:
IllegalArgumentException-iffromIndex>toIndex
ArrayIndexOutOfBoundsException-iffromIndex<0or
toIndex>a.length
ArrayStoreException-ifthespecifiedvalueisnotofa
runtimetypethatcanbestoredinthespecifiedarray
copyOf
publicstatic T[] copyOf(T[] original,
int newLength)
Copiesthespecifiedarray,truncatingorpaddingwithnulls(ifnecessary)
sothecopyhasthespecifiedlength.Forallindicesthatare
validinboththeoriginalarrayandthecopy,thetwoarrayswill
containidenticalvalues.Foranyindicesthatarevalidinthe
copybutnottheoriginal,thecopywillcontainnull.
Suchindiceswillexistifandonlyifthespecifiedlength
isgreaterthanthatoftheoriginalarray.
Theresultingarrayisofexactlythesameclassastheoriginalarray.
Parameters:original-thearraytobecopiednewLength-thelengthofthecopytobereturned
Returns:acopyoftheoriginalarray,truncatedorpaddedwithnulls
toobtainthespecifiedlength
Throws:
NegativeArraySizeException-ifnewLengthisnegative
NullPointerException-iforiginalisnullSince:
1.6
copyOf
publicstatic T[] copyOf(U[] original,
int newLength,
Class newType)
Copiesthespecifiedarray,truncatingorpaddingwithnulls(ifnecessary)
sothecopyhasthespecifiedlength.Forallindicesthatare
validinboththeoriginalarrayandthecopy,thetwoarrayswill
containidenticalvalues.Foranyindicesthatarevalidinthe
copybutnottheoriginal,thecopywillcontainnull.
Suchindiceswillexistifandonlyifthespecifiedlength
isgreaterthanthatoftheoriginalarray.
TheresultingarrayisoftheclassnewType.
Parameters:original-thearraytobecopiednewLength-thelengthofthecopytobereturnednewType-theclassofthecopytobereturned
Returns:acopyoftheoriginalarray,truncatedorpaddedwithnulls
toobtainthespecifiedlength
Throws:
NegativeArraySizeException-ifnewLengthisnegative
NullPointerException-iforiginalisnull
ArrayStoreException-ifanelementcopiedfrom
originalisnotofaruntimetypethatcanbestoredin
anarrayofclassnewTypeSince:
1.6
copyOf
publicstatic byte[] copyOf(byte[] original,
int newLength)
Copiesthespecifiedarray,truncatingorpaddingwithzeros(ifnecessary)
sothecopyhasthespecifiedlength.Forallindicesthatare
validinboththeoriginalarrayandthecopy,thetwoarrayswill
containidenticalvalues.Foranyindicesthatarevalidinthe
copybutnottheoriginal,thecopywillcontain(byte)0.
Suchindiceswillexistifandonlyifthespecifiedlength
isgreaterthanthatoftheoriginalarray.
Parameters:original-thearraytobecopiednewLength-thelengthofthecopytobereturned
Returns:acopyoftheoriginalarray,truncatedorpaddedwithzeros
toobtainthespecifiedlength
Throws:
NegativeArraySizeException-ifnewLengthisnegative
NullPointerException-iforiginalisnullSince:
1.6
copyOf
publicstatic short[] copyOf(short[] original,
int newLength)
Copiesthespecifiedarray,truncatingorpaddingwithzeros(ifnecessary)
sothecopyhasthespecifiedlength.Forallindicesthatare
validinboththeoriginalarrayandthecopy,thetwoarrayswill
containidenticalvalues.Foranyindicesthatarevalidinthe
copybutnottheoriginal,thecopywillcontain(short)0.
Suchindiceswillexistifandonlyifthespecifiedlength
isgreaterthanthatoftheoriginalarray.
Parameters:original-thearraytobecopiednewLength-thelengthofthecopytobereturned
Returns:acopyoftheoriginalarray,truncatedorpaddedwithzeros
toobtainthespecifiedlength
Throws:
NegativeArraySizeException-ifnewLengthisnegative
NullPointerException-iforiginalisnullSince:
1.6
copyOf
publicstatic int[] copyOf(int[] original,
int newLength)
Copiesthespecifiedarray,truncatingorpaddingwithzeros(ifnecessary)
sothecopyhasthespecifiedlength.Forallindicesthatare
validinboththeoriginalarrayandthecopy,thetwoarrayswill
containidenticalvalues.Foranyindicesthatarevalidinthe
copybutnottheoriginal,thecopywillcontain0.
Suchindiceswillexistifandonlyifthespecifiedlength
isgreaterthanthatoftheoriginalarray.
Parameters:original-thearraytobecopiednewLength-thelengthofthecopytobereturned
Returns:acopyoftheoriginalarray,truncatedorpaddedwithzeros
toobtainthespecifiedlength
Throws:
NegativeArraySizeException-ifnewLengthisnegative
NullPointerException-iforiginalisnullSince:
1.6
copyOf
publicstatic long[] copyOf(long[] original,
int newLength)
Copiesthespecifiedarray,truncatingorpaddingwithzeros(ifnecessary)
sothecopyhasthespecifiedlength.Forallindicesthatare
validinboththeoriginalarrayandthecopy,thetwoarrayswill
containidenticalvalues.Foranyindicesthatarevalidinthe
copybutnottheoriginal,thecopywillcontain0L.
Suchindiceswillexistifandonlyifthespecifiedlength
isgreaterthanthatoftheoriginalarray.
Parameters:original-thearraytobecopiednewLength-thelengthofthecopytobereturned
Returns:acopyoftheoriginalarray,truncatedorpaddedwithzeros
toobtainthespecifiedlength
Throws:
NegativeArraySizeException-ifnewLengthisnegative
NullPointerException-iforiginalisnullSince:
1.6
copyOf
publicstatic char[] copyOf(char[] original,
int newLength)
Copiesthespecifiedarray,truncatingorpaddingwithnullcharacters(ifnecessary)
sothecopyhasthespecifiedlength.Forallindicesthatarevalid
inboththeoriginalarrayandthecopy,thetwoarrayswillcontain
identicalvalues.Foranyindicesthatarevalidinthecopybutnot
theoriginal,thecopywillcontain'\\u000'.Suchindices
willexistifandonlyifthespecifiedlengthisgreaterthanthatof
theoriginalarray.
Parameters:original-thearraytobecopiednewLength-thelengthofthecopytobereturned
Returns:acopyoftheoriginalarray,truncatedorpaddedwithnullcharacters
toobtainthespecifiedlength
Throws:
NegativeArraySizeException-ifnewLengthisnegative
NullPointerException-iforiginalisnullSince:
1.6
copyOf
publicstatic float[] copyOf(float[] original,
int newLength)
Copiesthespecifiedarray,truncatingorpaddingwithzeros(ifnecessary)
sothecopyhasthespecifiedlength.Forallindicesthatare
validinboththeoriginalarrayandthecopy,thetwoarrayswill
containidenticalvalues.Foranyindicesthatarevalidinthe
copybutnottheoriginal,thecopywillcontain0f.
Suchindiceswillexistifandonlyifthespecifiedlength
isgreaterthanthatoftheoriginalarray.
Parameters:original-thearraytobecopiednewLength-thelengthofthecopytobereturned
Returns:acopyoftheoriginalarray,truncatedorpaddedwithzeros
toobtainthespecifiedlength
Throws:
NegativeArraySizeException-ifnewLengthisnegative
NullPointerException-iforiginalisnullSince:
1.6
copyOf
publicstatic double[] copyOf(double[] original,
int newLength)
Copiesthespecifiedarray,truncatingorpaddingwithzeros(ifnecessary)
sothecopyhasthespecifiedlength.Forallindicesthatare
validinboththeoriginalarrayandthecopy,thetwoarrayswill
containidenticalvalues.Foranyindicesthatarevalidinthe
copybutnottheoriginal,thecopywillcontain0d.
Suchindiceswillexistifandonlyifthespecifiedlength
isgreaterthanthatoftheoriginalarray.
Parameters:original-thearraytobecopiednewLength-thelengthofthecopytobereturned
Returns:acopyoftheoriginalarray,truncatedorpaddedwithzeros
toobtainthespecifiedlength
Throws:
NegativeArraySizeException-ifnewLengthisnegative
NullPointerException-iforiginalisnullSince:
1.6
copyOf
publicstatic boolean[] copyOf(boolean[] original,
int newLength)
Copiesthespecifiedarray,truncatingorpaddingwithfalse(ifnecessary)
sothecopyhasthespecifiedlength.Forallindicesthatare
validinboththeoriginalarrayandthecopy,thetwoarrayswill
containidenticalvalues.Foranyindicesthatarevalidinthe
copybutnottheoriginal,thecopywillcontainfalse.
Suchindiceswillexistifandonlyifthespecifiedlength
isgreaterthanthatoftheoriginalarray.
Parameters:original-thearraytobecopiednewLength-thelengthofthecopytobereturned
Returns:acopyoftheoriginalarray,truncatedorpaddedwithfalseelements
toobtainthespecifiedlength
Throws:
NegativeArraySizeException-ifnewLengthisnegative
NullPointerException-iforiginalisnullSince:
1.6
copyOfRange
publicstatic T[] copyOfRange(T[] original,
int from,
int to)
Copiesthespecifiedrangeofthespecifiedarrayintoanewarray.
Theinitialindexoftherange(from)mustliebetweenzero
andoriginal.length,inclusive.Thevalueat
original[from]isplacedintotheinitialelementofthecopy
(unlessfrom==original.lengthorfrom==to).
Valuesfromsubsequentelementsintheoriginalarrayareplacedinto
subsequentelementsinthecopy.Thefinalindexoftherange
(to),whichmustbegreaterthanorequaltofrom,
maybegreaterthanoriginal.length,inwhichcase
nullisplacedinallelementsofthecopywhoseindexis
greaterthanorequaltooriginal.length-from.Thelength
ofthereturnedarraywillbeto-from.
Theresultingarrayisofexactlythesameclassastheoriginalarray.
Parameters:original-thearrayfromwhicharangeistobecopiedfrom-theinitialindexoftherangetobecopied,inclusiveto-thefinalindexoftherangetobecopied,exclusive.
(Thisindexmaylieoutsidethearray.)
Returns:anewarraycontainingthespecifiedrangefromtheoriginalarray,
truncatedorpaddedwithnullstoobtaintherequiredlength
Throws:
ArrayIndexOutOfBoundsException-iffrom<0
orfrom>original.length
IllegalArgumentException-iffrom>to
NullPointerException-iforiginalisnullSince:
1.6
copyOfRange
publicstatic T[] copyOfRange(U[] original,
int from,
int to,
Class newType)
Copiesthespecifiedrangeofthespecifiedarrayintoanewarray.
Theinitialindexoftherange(from)mustliebetweenzero
andoriginal.length,inclusive.Thevalueat
original[from]isplacedintotheinitialelementofthecopy
(unlessfrom==original.lengthorfrom==to).
Valuesfromsubsequentelementsintheoriginalarrayareplacedinto
subsequentelementsinthecopy.Thefinalindexoftherange
(to),whichmustbegreaterthanorequaltofrom,
maybegreaterthanoriginal.length,inwhichcase
nullisplacedinallelementsofthecopywhoseindexis
greaterthanorequaltooriginal.length-from.Thelength
ofthereturnedarraywillbeto-from.
TheresultingarrayisoftheclassnewType.
Parameters:original-thearrayfromwhicharangeistobecopiedfrom-theinitialindexoftherangetobecopied,inclusiveto-thefinalindexoftherangetobecopied,exclusive.
(Thisindexmaylieoutsidethearray.)newType-theclassofthecopytobereturned
Returns:anewarraycontainingthespecifiedrangefromtheoriginalarray,
truncatedorpaddedwithnullstoobtaintherequiredlength
Throws:
ArrayIndexOutOfBoundsException-iffrom<0
orfrom>original.length
IllegalArgumentException-iffrom>to
NullPointerException-iforiginalisnull
ArrayStoreException-ifanelementcopiedfrom
originalisnotofaruntimetypethatcanbestoredin
anarrayofclassnewType.Since:
1.6
copyOfRange
publicstatic byte[] copyOfRange(byte[] original,
int from,
int to)
Copiesthespecifiedrangeofthespecifiedarrayintoanewarray.
Theinitialindexoftherange(from)mustliebetweenzero
andoriginal.length,inclusive.Thevalueat
original[from]isplacedintotheinitialelementofthecopy
(unlessfrom==original.lengthorfrom==to).
Valuesfromsubsequentelementsintheoriginalarrayareplacedinto
subsequentelementsinthecopy.Thefinalindexoftherange
(to),whichmustbegreaterthanorequaltofrom,
maybegreaterthanoriginal.length,inwhichcase
(byte)0isplacedinallelementsofthecopywhoseindexis
greaterthanorequaltooriginal.length-from.Thelength
ofthereturnedarraywillbeto-from.
Parameters:original-thearrayfromwhicharangeistobecopiedfrom-theinitialindexoftherangetobecopied,inclusiveto-thefinalindexoftherangetobecopied,exclusive.
(Thisindexmaylieoutsidethearray.)
Returns:anewarraycontainingthespecifiedrangefromtheoriginalarray,
truncatedorpaddedwithzerostoobtaintherequiredlength
Throws:
ArrayIndexOutOfBoundsException-iffrom<0
orfrom>original.length
IllegalArgumentException-iffrom>to
NullPointerException-iforiginalisnullSince:
1.6
copyOfRange
publicstatic short[] copyOfRange(short[] original,
int from,
int to)
Copiesthespecifiedrangeofthespecifiedarrayintoanewarray.
Theinitialindexoftherange(from)mustliebetweenzero
andoriginal.length,inclusive.Thevalueat
original[from]isplacedintotheinitialelementofthecopy
(unlessfrom==original.lengthorfrom==to).
Valuesfromsubsequentelementsintheoriginalarrayareplacedinto
subsequentelementsinthecopy.Thefinalindexoftherange
(to),whichmustbegreaterthanorequaltofrom,
maybegreaterthanoriginal.length,inwhichcase
(short)0isplacedinallelementsofthecopywhoseindexis
greaterthanorequaltooriginal.length-from.Thelength
ofthereturnedarraywillbeto-from.
Parameters:original-thearrayfromwhicharangeistobecopiedfrom-theinitialindexoftherangetobecopied,inclusiveto-thefinalindexoftherangetobecopied,exclusive.
(Thisindexmaylieoutsidethearray.)
Returns:anewarraycontainingthespecifiedrangefromtheoriginalarray,
truncatedorpaddedwithzerostoobtaintherequiredlength
Throws:
ArrayIndexOutOfBoundsException-iffrom<0
orfrom>original.length
IllegalArgumentException-iffrom>to
NullPointerException-iforiginalisnullSince:
1.6
copyOfRange
publicstatic int[] copyOfRange(int[] original,
int from,
int to)
Copiesthespecifiedrangeofthespecifiedarrayintoanewarray.
Theinitialindexoftherange(from)mustliebetweenzero
andoriginal.length,inclusive.Thevalueat
original[from]isplacedintotheinitialelementofthecopy
(unlessfrom==original.lengthorfrom==to).
Valuesfromsubsequentelementsintheoriginalarrayareplacedinto
subsequentelementsinthecopy.Thefinalindexoftherange
(to),whichmustbegreaterthanorequaltofrom,
maybegreaterthanoriginal.length,inwhichcase
0isplacedinallelementsofthecopywhoseindexis
greaterthanorequaltooriginal.length-from.Thelength
ofthereturnedarraywillbeto-from.
Parameters:original-thearrayfromwhicharangeistobecopiedfrom-theinitialindexoftherangetobecopied,inclusiveto-thefinalindexoftherangetobecopied,exclusive.
(Thisindexmaylieoutsidethearray.)
Returns:anewarraycontainingthespecifiedrangefromtheoriginalarray,
truncatedorpaddedwithzerostoobtaintherequiredlength
Throws:
ArrayIndexOutOfBoundsException-iffrom<0
orfrom>original.length
IllegalArgumentException-iffrom>to
NullPointerException-iforiginalisnullSince:
1.6
copyOfRange
publicstatic long[] copyOfRange(long[] original,
int from,
int to)
Copiesthespecifiedrangeofthespecifiedarrayintoanewarray.
Theinitialindexoftherange(from)mustliebetweenzero
andoriginal.length,inclusive.Thevalueat
original[from]isplacedintotheinitialelementofthecopy
(unlessfrom==original.lengthorfrom==to).
Valuesfromsubsequentelementsintheoriginalarrayareplacedinto
subsequentelementsinthecopy.Thefinalindexoftherange
(to),whichmustbegreaterthanorequaltofrom,
maybegreaterthanoriginal.length,inwhichcase
0Lisplacedinallelementsofthecopywhoseindexis
greaterthanorequaltooriginal.length-from.Thelength
ofthereturnedarraywillbeto-from.
Parameters:original-thearrayfromwhicharangeistobecopiedfrom-theinitialindexoftherangetobecopied,inclusiveto-thefinalindexoftherangetobecopied,exclusive.
(Thisindexmaylieoutsidethearray.)
Returns:anewarraycontainingthespecifiedrangefromtheoriginalarray,
truncatedorpaddedwithzerostoobtaintherequiredlength
Throws:
ArrayIndexOutOfBoundsException-iffrom<0
orfrom>original.length
IllegalArgumentException-iffrom>to
NullPointerException-iforiginalisnullSince:
1.6
copyOfRange
publicstatic char[] copyOfRange(char[] original,
int from,
int to)
Copiesthespecifiedrangeofthespecifiedarrayintoanewarray.
Theinitialindexoftherange(from)mustliebetweenzero
andoriginal.length,inclusive.Thevalueat
original[from]isplacedintotheinitialelementofthecopy
(unlessfrom==original.lengthorfrom==to).
Valuesfromsubsequentelementsintheoriginalarrayareplacedinto
subsequentelementsinthecopy.Thefinalindexoftherange
(to),whichmustbegreaterthanorequaltofrom,
maybegreaterthanoriginal.length,inwhichcase
'\\u000'isplacedinallelementsofthecopywhoseindexis
greaterthanorequaltooriginal.length-from.Thelength
ofthereturnedarraywillbeto-from.
Parameters:original-thearrayfromwhicharangeistobecopiedfrom-theinitialindexoftherangetobecopied,inclusiveto-thefinalindexoftherangetobecopied,exclusive.
(Thisindexmaylieoutsidethearray.)
Returns:anewarraycontainingthespecifiedrangefromtheoriginalarray,
truncatedorpaddedwithnullcharacterstoobtaintherequiredlength
Throws:
ArrayIndexOutOfBoundsException-iffrom<0
orfrom>original.length
IllegalArgumentException-iffrom>to
NullPointerException-iforiginalisnullSince:
1.6
copyOfRange
publicstatic float[] copyOfRange(float[] original,
int from,
int to)
Copiesthespecifiedrangeofthespecifiedarrayintoanewarray.
Theinitialindexoftherange(from)mustliebetweenzero
andoriginal.length,inclusive.Thevalueat
original[from]isplacedintotheinitialelementofthecopy
(unlessfrom==original.lengthorfrom==to).
Valuesfromsubsequentelementsintheoriginalarrayareplacedinto
subsequentelementsinthecopy.Thefinalindexoftherange
(to),whichmustbegreaterthanorequaltofrom,
maybegreaterthanoriginal.length,inwhichcase
0fisplacedinallelementsofthecopywhoseindexis
greaterthanorequaltooriginal.length-from.Thelength
ofthereturnedarraywillbeto-from.
Parameters:original-thearrayfromwhicharangeistobecopiedfrom-theinitialindexoftherangetobecopied,inclusiveto-thefinalindexoftherangetobecopied,exclusive.
(Thisindexmaylieoutsidethearray.)
Returns:anewarraycontainingthespecifiedrangefromtheoriginalarray,
truncatedorpaddedwithzerostoobtaintherequiredlength
Throws:
ArrayIndexOutOfBoundsException-iffrom<0
orfrom>original.length
IllegalArgumentException-iffrom>to
NullPointerException-iforiginalisnullSince:
1.6
copyOfRange
publicstatic double[] copyOfRange(double[] original,
int from,
int to)
Copiesthespecifiedrangeofthespecifiedarrayintoanewarray.
Theinitialindexoftherange(from)mustliebetweenzero
andoriginal.length,inclusive.Thevalueat
original[from]isplacedintotheinitialelementofthecopy
(unlessfrom==original.lengthorfrom==to).
Valuesfromsubsequentelementsintheoriginalarrayareplacedinto
subsequentelementsinthecopy.Thefinalindexoftherange
(to),whichmustbegreaterthanorequaltofrom,
maybegreaterthanoriginal.length,inwhichcase
0displacedinallelementsofthecopywhoseindexis
greaterthanorequaltooriginal.length-from.Thelength
ofthereturnedarraywillbeto-from.
Parameters:original-thearrayfromwhicharangeistobecopiedfrom-theinitialindexoftherangetobecopied,inclusiveto-thefinalindexoftherangetobecopied,exclusive.
(Thisindexmaylieoutsidethearray.)
Returns:anewarraycontainingthespecifiedrangefromtheoriginalarray,
truncatedorpaddedwithzerostoobtaintherequiredlength
Throws:
ArrayIndexOutOfBoundsException-iffrom<0
orfrom>original.length
IllegalArgumentException-iffrom>to
NullPointerException-iforiginalisnullSince:
1.6
copyOfRange
publicstatic boolean[] copyOfRange(boolean[] original,
int from,
int to)
Copiesthespecifiedrangeofthespecifiedarrayintoanewarray.
Theinitialindexoftherange(from)mustliebetweenzero
andoriginal.length,inclusive.Thevalueat
original[from]isplacedintotheinitialelementofthecopy
(unlessfrom==original.lengthorfrom==to).
Valuesfromsubsequentelementsintheoriginalarrayareplacedinto
subsequentelementsinthecopy.Thefinalindexoftherange
(to),whichmustbegreaterthanorequaltofrom,
maybegreaterthanoriginal.length,inwhichcase
falseisplacedinallelementsofthecopywhoseindexis
greaterthanorequaltooriginal.length-from.Thelength
ofthereturnedarraywillbeto-from.
Parameters:original-thearrayfromwhicharangeistobecopiedfrom-theinitialindexoftherangetobecopied,inclusiveto-thefinalindexoftherangetobecopied,exclusive.
(Thisindexmaylieoutsidethearray.)
Returns:anewarraycontainingthespecifiedrangefromtheoriginalarray,
truncatedorpaddedwithfalseelementstoobtaintherequiredlength
Throws:
ArrayIndexOutOfBoundsException-iffrom<0
orfrom>original.length
IllegalArgumentException-iffrom>to
NullPointerException-iforiginalisnullSince:
1.6
asList
@SafeVarargs
publicstatic List asList(T... a)
Returnsafixed-sizelistbackedbythespecifiedarray.(Changesto
thereturnedlist"writethrough"tothearray.)Thismethodacts
asbridgebetweenarray-basedandcollection-basedAPIs,in
combinationwithCollection.toArray().Thereturnedlistis
serializableandimplementsRandomAccess.
Thismethodalsoprovidesaconvenientwaytocreateafixed-size
listinitializedtocontainseveralelements:
Liststooges=Arrays.asList("Larry","Moe","Curly");
Parameters:a-thearraybywhichthelistwillbebacked
Returns:alistviewofthespecifiedarray
hashCode
publicstatic int hashCode(long[] a)
Returnsahashcodebasedonthecontentsofthespecifiedarray.
Foranytwolongarraysaandb
suchthatArrays.equals(a,b),itisalsothecasethat
Arrays.hashCode(a)==Arrays.hashCode(b).
Thevaluereturnedbythismethodisthesamevaluethatwouldbe
obtainedbyinvokingthehashCode
methodonaListcontainingasequenceofLong
instancesrepresentingtheelementsofainthesameorder.
Ifaisnull,thismethodreturns0.
Parameters:a-thearraywhosehashvaluetocompute
Returns:acontent-basedhashcodeforaSince:
1.5
hashCode
publicstatic int hashCode(int[] a)
Returnsahashcodebasedonthecontentsofthespecifiedarray.
Foranytwonon-nullintarraysaandb
suchthatArrays.equals(a,b),itisalsothecasethat
Arrays.hashCode(a)==Arrays.hashCode(b).
Thevaluereturnedbythismethodisthesamevaluethatwouldbe
obtainedbyinvokingthehashCode
methodonaListcontainingasequenceofInteger
instancesrepresentingtheelementsofainthesameorder.
Ifaisnull,thismethodreturns0.
Parameters:a-thearraywhosehashvaluetocompute
Returns:acontent-basedhashcodeforaSince:
1.5
hashCode
publicstatic int hashCode(short[] a)
Returnsahashcodebasedonthecontentsofthespecifiedarray.
Foranytwoshortarraysaandb
suchthatArrays.equals(a,b),itisalsothecasethat
Arrays.hashCode(a)==Arrays.hashCode(b).
Thevaluereturnedbythismethodisthesamevaluethatwouldbe
obtainedbyinvokingthehashCode
methodonaListcontainingasequenceofShort
instancesrepresentingtheelementsofainthesameorder.
Ifaisnull,thismethodreturns0.
Parameters:a-thearraywhosehashvaluetocompute
Returns:acontent-basedhashcodeforaSince:
1.5
hashCode
publicstatic int hashCode(char[] a)
Returnsahashcodebasedonthecontentsofthespecifiedarray.
Foranytwochararraysaandb
suchthatArrays.equals(a,b),itisalsothecasethat
Arrays.hashCode(a)==Arrays.hashCode(b).
Thevaluereturnedbythismethodisthesamevaluethatwouldbe
obtainedbyinvokingthehashCode
methodonaListcontainingasequenceofCharacter
instancesrepresentingtheelementsofainthesameorder.
Ifaisnull,thismethodreturns0.
Parameters:a-thearraywhosehashvaluetocompute
Returns:acontent-basedhashcodeforaSince:
1.5
hashCode
publicstatic int hashCode(byte[] a)
Returnsahashcodebasedonthecontentsofthespecifiedarray.
Foranytwobytearraysaandb
suchthatArrays.equals(a,b),itisalsothecasethat
Arrays.hashCode(a)==Arrays.hashCode(b).
Thevaluereturnedbythismethodisthesamevaluethatwouldbe
obtainedbyinvokingthehashCode
methodonaListcontainingasequenceofByte
instancesrepresentingtheelementsofainthesameorder.
Ifaisnull,thismethodreturns0.
Parameters:a-thearraywhosehashvaluetocompute
Returns:acontent-basedhashcodeforaSince:
1.5
hashCode
publicstatic int hashCode(boolean[] a)
Returnsahashcodebasedonthecontentsofthespecifiedarray.
Foranytwobooleanarraysaandb
suchthatArrays.equals(a,b),itisalsothecasethat
Arrays.hashCode(a)==Arrays.hashCode(b).
Thevaluereturnedbythismethodisthesamevaluethatwouldbe
obtainedbyinvokingthehashCode
methodonaListcontainingasequenceofBoolean
instancesrepresentingtheelementsofainthesameorder.
Ifaisnull,thismethodreturns0.
Parameters:a-thearraywhosehashvaluetocompute
Returns:acontent-basedhashcodeforaSince:
1.5
hashCode
publicstatic int hashCode(float[] a)
Returnsahashcodebasedonthecontentsofthespecifiedarray.
Foranytwofloatarraysaandb
suchthatArrays.equals(a,b),itisalsothecasethat
Arrays.hashCode(a)==Arrays.hashCode(b).
Thevaluereturnedbythismethodisthesamevaluethatwouldbe
obtainedbyinvokingthehashCode
methodonaListcontainingasequenceofFloat
instancesrepresentingtheelementsofainthesameorder.
Ifaisnull,thismethodreturns0.
Parameters:a-thearraywhosehashvaluetocompute
Returns:acontent-basedhashcodeforaSince:
1.5
hashCode
publicstatic int hashCode(double[] a)
Returnsahashcodebasedonthecontentsofthespecifiedarray.
Foranytwodoublearraysaandb
suchthatArrays.equals(a,b),itisalsothecasethat
Arrays.hashCode(a)==Arrays.hashCode(b).
Thevaluereturnedbythismethodisthesamevaluethatwouldbe
obtainedbyinvokingthehashCode
methodonaListcontainingasequenceofDouble
instancesrepresentingtheelementsofainthesameorder.
Ifaisnull,thismethodreturns0.
Parameters:a-thearraywhosehashvaluetocompute
Returns:acontent-basedhashcodeforaSince:
1.5
hashCode
publicstatic int hashCode(Object[] a)
Returnsahashcodebasedonthecontentsofthespecifiedarray.If
thearraycontainsotherarraysaselements,thehashcodeisbasedon
theiridentitiesratherthantheircontents.Itistherefore
acceptabletoinvokethismethodonanarraythatcontainsitselfasan
element,eitherdirectlyorindirectlythroughoneormorelevelsof
arrays.
Foranytwoarraysaandbsuchthat
Arrays.equals(a,b),itisalsothecasethat
Arrays.hashCode(a)==Arrays.hashCode(b).
Thevaluereturnedbythismethodisequaltothevaluethatwould
bereturnedbyArrays.asList(a).hashCode(),unlessa
isnull,inwhichcase0isreturned.
Parameters:a-thearraywhosecontent-basedhashcodetocompute
Returns:acontent-basedhashcodeforaSince:
1.5
SeeAlso:deepHashCode(Object[])
deepHashCode
publicstatic int deepHashCode(Object[] a)
Returnsahashcodebasedonthe"deepcontents"ofthespecified
array.Ifthearraycontainsotherarraysaselements,the
hashcodeisbasedontheircontentsandsoon,adinfinitum.
Itisthereforeunacceptabletoinvokethismethodonanarraythat
containsitselfasanelement,eitherdirectlyorindirectlythrough
oneormorelevelsofarrays.Thebehaviorofsuchaninvocationis
undefined.
Foranytwoarraysaandbsuchthat
Arrays.deepEquals(a,b),itisalsothecasethat
Arrays.deepHashCode(a)==Arrays.deepHashCode(b).
Thecomputationofthevaluereturnedbythismethodissimilarto
thatofthevaluereturnedbyList.hashCode()onalist
containingthesameelementsasainthesameorder,withone
difference:Ifanelementeofaisitselfanarray,
itshashcodeiscomputednotbycallinge.hashCode(),butas
bycallingtheappropriateoverloadingofArrays.hashCode(e)
ifeisanarrayofaprimitivetype,orasbycalling
Arrays.deepHashCode(e)recursivelyifeisanarray
ofareferencetype.Ifaisnull,thismethod
returns0.
Parameters:a-thearraywhosedeep-content-basedhashcodetocompute
Returns:adeep-content-basedhashcodeforaSince:
1.5
SeeAlso:hashCode(Object[])
deepEquals
publicstatic boolean deepEquals(Object[] a1,
Object[] a2)
Returnstrueifthetwospecifiedarraysaredeeply
equaltooneanother.Unliketheequals(Object[],Object[])
method,thismethodisappropriateforusewithnestedarraysof
arbitrarydepth.
Twoarrayreferencesareconsidereddeeplyequalifboth
arenull,oriftheyrefertoarraysthatcontainthesame
numberofelementsandallcorrespondingpairsofelementsinthetwo
arraysaredeeplyequal.
Twopossiblynullelementse1ande2are
deeplyequalifanyofthefollowingconditionshold:
e1ande2arebotharraysofobjectreference
types,andArrays.deepEquals(e1,e2)wouldreturntrue
e1ande2arearraysofthesameprimitive
type,andtheappropriateoverloadingof
Arrays.equals(e1,e2)wouldreturntrue.
e1==e2
e1.equals(e2)wouldreturntrue.
Notethatthisdefinitionpermitsnullelementsatanydepth.
Ifeitherofthespecifiedarrayscontainthemselvesaselements
eitherdirectlyorindirectlythroughoneormorelevelsofarrays,
thebehaviorofthismethodisundefined.
Parameters:a1-onearraytobetestedforequalitya2-theotherarraytobetestedforequality
Returns:trueifthetwoarraysareequalSince:
1.5
SeeAlso:equals(Object[],Object[]),
Objects.deepEquals(Object,Object)
toString
publicstatic String toString(long[] a)
Returnsastringrepresentationofthecontentsofthespecifiedarray.
Thestringrepresentationconsistsofalistofthearray'selements,
enclosedinsquarebrackets("[]").Adjacentelementsare
separatedbythecharacters","(acommafollowedbya
space).Elementsareconvertedtostringsasby
String.valueOf(long).Returns"null"ifa
isnull.
Parameters:a-thearraywhosestringrepresentationtoreturn
Returns:astringrepresentationofaSince:
1.5
toString
publicstatic String toString(int[] a)
Returnsastringrepresentationofthecontentsofthespecifiedarray.
Thestringrepresentationconsistsofalistofthearray'selements,
enclosedinsquarebrackets("[]").Adjacentelementsare
separatedbythecharacters","(acommafollowedbya
space).Elementsareconvertedtostringsasby
String.valueOf(int).Returns"null"ifais
null.
Parameters:a-thearraywhosestringrepresentationtoreturn
Returns:astringrepresentationofaSince:
1.5
toString
publicstatic String toString(short[] a)
Returnsastringrepresentationofthecontentsofthespecifiedarray.
Thestringrepresentationconsistsofalistofthearray'selements,
enclosedinsquarebrackets("[]").Adjacentelementsare
separatedbythecharacters","(acommafollowedbya
space).Elementsareconvertedtostringsasby
String.valueOf(short).Returns"null"ifa
isnull.
Parameters:a-thearraywhosestringrepresentationtoreturn
Returns:astringrepresentationofaSince:
1.5
toString
publicstatic String toString(char[] a)
Returnsastringrepresentationofthecontentsofthespecifiedarray.
Thestringrepresentationconsistsofalistofthearray'selements,
enclosedinsquarebrackets("[]").Adjacentelementsare
separatedbythecharacters","(acommafollowedbya
space).Elementsareconvertedtostringsasby
String.valueOf(char).Returns"null"ifa
isnull.
Parameters:a-thearraywhosestringrepresentationtoreturn
Returns:astringrepresentationofaSince:
1.5
toString
publicstatic String toString(byte[] a)
Returnsastringrepresentationofthecontentsofthespecifiedarray.
Thestringrepresentationconsistsofalistofthearray'selements,
enclosedinsquarebrackets("[]").Adjacentelements
areseparatedbythecharacters","(acommafollowed
byaspace).Elementsareconvertedtostringsasby
String.valueOf(byte).Returns"null"if
aisnull.
Parameters:a-thearraywhosestringrepresentationtoreturn
Returns:astringrepresentationofaSince:
1.5
toString
publicstatic String toString(boolean[] a)
Returnsastringrepresentationofthecontentsofthespecifiedarray.
Thestringrepresentationconsistsofalistofthearray'selements,
enclosedinsquarebrackets("[]").Adjacentelementsare
separatedbythecharacters","(acommafollowedbya
space).Elementsareconvertedtostringsasby
String.valueOf(boolean).Returns"null"if
aisnull.
Parameters:a-thearraywhosestringrepresentationtoreturn
Returns:astringrepresentationofaSince:
1.5
toString
publicstatic String toString(float[] a)
Returnsastringrepresentationofthecontentsofthespecifiedarray.
Thestringrepresentationconsistsofalistofthearray'selements,
enclosedinsquarebrackets("[]").Adjacentelementsare
separatedbythecharacters","(acommafollowedbya
space).Elementsareconvertedtostringsasby
String.valueOf(float).Returns"null"ifa
isnull.
Parameters:a-thearraywhosestringrepresentationtoreturn
Returns:astringrepresentationofaSince:
1.5
toString
publicstatic String toString(double[] a)
Returnsastringrepresentationofthecontentsofthespecifiedarray.
Thestringrepresentationconsistsofalistofthearray'selements,
enclosedinsquarebrackets("[]").Adjacentelementsare
separatedbythecharacters","(acommafollowedbya
space).Elementsareconvertedtostringsasby
String.valueOf(double).Returns"null"ifa
isnull.
Parameters:a-thearraywhosestringrepresentationtoreturn
Returns:astringrepresentationofaSince:
1.5
toString
publicstatic String toString(Object[] a)
Returnsastringrepresentationofthecontentsofthespecifiedarray.
Ifthearraycontainsotherarraysaselements,theyareconvertedto
stringsbytheObject.toString()methodinheritedfrom
Object,whichdescribestheiridentitiesratherthan
theircontents.
Thevaluereturnedbythismethodisequaltothevaluethatwould
bereturnedbyArrays.asList(a).toString(),unlessa
isnull,inwhichcase"null"isreturned.
Parameters:a-thearraywhosestringrepresentationtoreturn
Returns:astringrepresentationofaSince:
1.5
SeeAlso:deepToString(Object[])
deepToString
publicstatic String deepToString(Object[] a)
Returnsastringrepresentationofthe"deepcontents"ofthespecified
array.Ifthearraycontainsotherarraysaselements,thestring
representationcontainstheircontentsandsoon.Thismethodis
designedforconvertingmultidimensionalarraystostrings.
Thestringrepresentationconsistsofalistofthearray's
elements,enclosedinsquarebrackets("[]").Adjacent
elementsareseparatedbythecharacters","(acomma
followedbyaspace).Elementsareconvertedtostringsasby
String.valueOf(Object),unlesstheyarethemselves
arrays.
Ifanelementeisanarrayofaprimitivetype,itis
convertedtoastringasbyinvokingtheappropriateoverloadingof
Arrays.toString(e).Ifanelementeisanarrayofa
referencetype,itisconvertedtoastringasbyinvoking
thismethodrecursively.
Toavoidinfiniterecursion,ifthespecifiedarraycontainsitself
asanelement,orcontainsanindirectreferencetoitselfthroughone
ormorelevelsofarrays,theself-referenceisconvertedtothestring
"[...]".Forexample,anarraycontainingonlyareference
toitselfwouldberenderedas"[[...]]".
Thismethodreturns"null"ifthespecifiedarray
isnull.
Parameters:a-thearraywhosestringrepresentationtoreturn
Returns:astringrepresentationofaSince:
1.5
SeeAlso:toString(Object[])
Overview
Package
Class
Use
Tree
Deprecated
Index
Help
Java™ PlatformStandard Ed. 7
PrevClass
NextClass
Frames
NoFrames
AllClasses
Summary:
Nested |
Field |
Constr |
Method
Detail:
Field |
Constr |
Method
SubmitabugorfeatureForfurtherAPIreferenceanddeveloperdocumentation,seeJavaSEDocumentation.Thatdocumentationcontainsmoredetailed,developer-targeteddescriptions,withconceptualoverviews,definitionsofterms,workarounds,andworkingcodeexamples.Copyright©1993,2020,Oracleand/oritsaffiliates.Allrightsreserved.Useissubjecttolicenseterms.Alsoseethedocumentationredistributionpolicy.