KickJava   Java API By Example, From Geeks To Geeks.

Java > Java SE, EE, ME > java > util > Arrays

java.util
Class Arrays

java.lang.Object
  extended by java.util.Arrays
See Also:
Top Examples, Source Code, Comparable, Comparator

public static List asList(Object[] a)
See Also:
Collection.toArray()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1520]Test array as list
By mohammed_coleman { at } hotmail on 2005/08/21 04:58:03  Rate
import java.util.*; 
  
  
 public class TestAsList 
  {  
   public static void main  ( String ... args  )  //J2SE 5.0 
    {  
     String [  ]  names = new String [  ]  { "TestA", "TestB", "TestC" } ; 
     List listOfNames = new ArrayList (  ) ; 
     listOfNames = Arrays.asList ( names ) ; 
     System.out.println ( "As List: " + listOfNames ) ; 
    }  
  } 


public static <T> List<T> asList(T... a)
See Also:
Collection.toArray(), RandomAccess
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static int binarySearch(byte[] a,
                               byte key)
See Also:
sort(byte[])
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static int binarySearch(char[] a,
                               char key)
See Also:
sort(char[])
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static int binarySearch(double[] a,
                               double key)
See Also:
sort(double[])
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static int binarySearch(float[] a,
                               float key)
See Also:
sort(float[])
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static int binarySearch(int[] a,
                               int key)
See Also:
sort(int[])
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static int binarySearch(Object[] a,
                               Object key)
See Also:
sort(Object[]), Comparable, ClassCastException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static int binarySearch(Object[] a,
                               Object key,
                               Comparator c)
See Also:
sort(Object[], Comparator), Comparable, ClassCastException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static int binarySearch(long[] a,
                               long key)
See Also:
sort(long[])
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static int binarySearch(short[] a,
                               short key)
See Also:
sort(short[])
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static <T> int binarySearch(T[] a,
                                   T key,
                                   Comparator<? super T> c)
See Also:
sort(Object[], Comparator), Comparable, ClassCastException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static boolean deepEquals(Object[] a1,
                                 Object[] a2)
See Also:
equals(Object[],Object[])
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static int deepHashCode(Object[] a)
See Also:
hashCode(Object[]), List.hashCode()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static String deepToString(Object[] a)
See Also:
toString(Object[])
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static boolean equals(boolean[] a,
                             boolean[] a2)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static boolean equals(byte[] a,
                             byte[] a2)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static boolean equals(char[] a,
                             char[] a2)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static boolean equals(double[] a,
                             double[] a2)
See Also:
Double.equals(Object)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static boolean equals(float[] a,
                             float[] a2)
See Also:
Float.equals(Object)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static boolean equals(int[] a,
                             int[] a2)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static boolean equals(Object[] a,
                             Object[] a2)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static boolean equals(long[] a,
                             long[] a2)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static boolean equals(short[] a,
                             short[] a2)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void fill(boolean[] a,
                        boolean val)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void fill(boolean[] a,
                        int fromIndex,
                        int toIndex,
                        boolean val)
See Also:
ArrayIndexOutOfBoundsException, IllegalArgumentException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void fill(byte[] a,
                        byte val)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void fill(byte[] a,
                        int fromIndex,
                        int toIndex,
                        byte val)
See Also:
ArrayIndexOutOfBoundsException, IllegalArgumentException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void fill(char[] a,
                        char val)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void fill(char[] a,
                        int fromIndex,
                        int toIndex,
                        char val)
See Also:
ArrayIndexOutOfBoundsException, IllegalArgumentException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void fill(double[] a,
                        double val)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void fill(double[] a,
                        int fromIndex,
                        int toIndex,
                        double val)
See Also:
ArrayIndexOutOfBoundsException, IllegalArgumentException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void fill(float[] a,
                        float val)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void fill(float[] a,
                        int fromIndex,
                        int toIndex,
                        float val)
See Also:
ArrayIndexOutOfBoundsException, IllegalArgumentException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void fill(int[] a,
                        int val)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void fill(int[] a,
                        int fromIndex,
                        int toIndex,
                        int val)
See Also:
ArrayIndexOutOfBoundsException, IllegalArgumentException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void fill(Object[] a,
                        int fromIndex,
                        int toIndex,
                        Object val)
See Also:
ArrayIndexOutOfBoundsException, IllegalArgumentException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void fill(Object[] a,
                        Object val)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void fill(long[] a,
                        int fromIndex,
                        int toIndex,
                        long val)
See Also:
ArrayIndexOutOfBoundsException, IllegalArgumentException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void fill(long[] a,
                        long val)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void fill(short[] a,
                        int fromIndex,
                        int toIndex,
                        short val)
See Also:
ArrayIndexOutOfBoundsException, IllegalArgumentException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void fill(short[] a,
                        short val)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static int hashCode(boolean[] a)
See Also:
Boolean, List, hashCode
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static int hashCode(byte[] a)
See Also:
Byte, List, hashCode
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static int hashCode(char[] a)
See Also:
Character, List, hashCode
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static int hashCode(double[] a)
See Also:
Double, List, hashCode
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static int hashCode(float[] a)
See Also:
Float, List, hashCode
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static int hashCode(int[] a)
See Also:
Integer, List, hashCode
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static int hashCode(Object[] a)
See Also:
deepHashCode(Object[])
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static int hashCode(long[] a)
See Also:
Long, List, hashCode
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static int hashCode(short[] a)
See Also:
Short, List, hashCode
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void sort(byte[] a)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void sort(byte[] a,
                        int fromIndex,
                        int toIndex)
See Also:
ArrayIndexOutOfBoundsException, IllegalArgumentException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void sort(char[] a)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void sort(char[] a,
                        int fromIndex,
                        int toIndex)
See Also:
ArrayIndexOutOfBoundsException, IllegalArgumentException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void sort(double[] a)
See Also:
Double.compareTo(java.lang.Double)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[844]How to sort an array using java.util.Arrays Sort???
By Anonymous on 2004/07/27 05:14:37  Rate
 
 Hi, 
 I would like to know how to sort an array using java.util.Arrays Sort. 
 I have generate 100 random values for the array arr and I would like 
 to sort it. I have tried to sort it without success. 
  
  
 import cern.jet.random.AbstractDistribution; 
 import cern.jet.random.engine.RandomSeedGenerator; 
 import cern.jet.random.engine.MersenneTwister; 
 import cern.colt.Sorting; 
 import java.util.Arrays; 
 import javax.swing.*; 
  
  
  
 public class Gauss 
  {  
   public static void main  ( String args [  ]  )  
     {  
       Gauss div = new Gauss (  ) ;      
     }  
  
  
 public Gauss (  )  
  {      
 double  [  ]  arr= new double [ 100 ] ; 
 double cas; 
 double mean = 0; 
 double variance = 1; 
 cern.jet.random.engine.RandomEngine engine = new cern.jet.random.engine.MersenneTwister ( new java.util.Date (  )  ) ;  
 cern.jet.random.AbstractDistribution dist = new cern.jet.random.Normal ( mean,variance,engine ) ; 
  
  
 for  ( int i=0; i < arr.length; i++ )  
    {  
   arr [ i ] =dist.nextDouble (  ) ; 
    
    }  
  }  
  
  
  
  
                             
                        
  }  
 I woul like to know how to sort the array arr using sort ( double [  ]  )  
 Could someone suggest me the code? 
 Thank you very much for your help. 
 My best regards. gm


public static void sort(double[] a,
                        int fromIndex,
                        int toIndex)
See Also:
ArrayIndexOutOfBoundsException, IllegalArgumentException, Double.compareTo(java.lang.Double)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void sort(float[] a)
See Also:
Float.compareTo(java.lang.Float)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void sort(float[] a,
                        int fromIndex,
                        int toIndex)
See Also:
ArrayIndexOutOfBoundsException, IllegalArgumentException, Float.compareTo(java.lang.Float)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void sort(int[] a)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[19]Sort numberic array
By Max Okist on 2002/08/07 23:02:26  Rate
int [  ]  numberArray =  { 5, 12, 4, 2, 26, 9, 23, 14 ) ; 
 Arrays.sort ( numberArray ) ;


public static void sort(int[] a,
                        int fromIndex,
                        int toIndex)
See Also:
ArrayIndexOutOfBoundsException, IllegalArgumentException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void sort(Object[] a)
See Also:
Comparable, ClassCastException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1338]String type ArrayList
By Anonymous on 2005/03/11 01:29:15  Rate
    ArrayList < String >  a = new ArrayList < String >  ( 5 ) ; 
      
     a.add ( "cccccccccc" ) ; 
     a.add ( "eeeeeeeeeeeeeee" ) ; 
     a.add ( "aaaaaaaaaaaa" ) ; 
     a.add ( "dddddddddddd" ) ; 
     a.add ( "bbbbbbbbbbb" ) ; 
      
     Object [  ]  ar = a.toArray (  ) ; 
     Arrays.sort ( ar ) ; 
          
     for ( Object str: ar )  {  
       System.out.println ( str ) ; 
      }  
 


public static void sort(Object[] a,
                        int fromIndex,
                        int toIndex)
See Also:
Comparable, ClassCastException, ArrayIndexOutOfBoundsException, IllegalArgumentException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void sort(Object[] a,
                        int fromIndex,
                        int toIndex,
                        Comparator c)
See Also:
ArrayIndexOutOfBoundsException, IllegalArgumentException, ClassCastException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void sort(Object[] a,
                        Comparator c)
See Also:
ClassCastException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1339]Sort array with a comparator
By friend_rival { at } yahoo { dot } com on 2005/06/20 14:59:35  Rate
import java.util.*; 
 public class TestPart1  {  
   public TestPart1 (  )   {  
     // TODO Auto-generated constructor stub 
    }  
   public void testLoop (  )  {  
     ArrayList < String >  a = new ArrayList < String >  ( 5 ) ; 
      
     a.add ( "cccccccccc" ) ; 
     a.add ( "eeeeeeeeeeeeeee" ) ; 
     a.add ( "aaaaaaaaaaaa" ) ; 
     a.add ( "dddddddddddd" ) ; 
     a.add ( "bbbbbbbbbbb" ) ; 
      
     List l = Arrays.asList ( a.toArray (  )  ) ; 
     Collections.sort ( l, new MyComparer (  )   ) ; 
          
     for (  Object str : l.toArray (  )  )  {  
       System.out.println ( str ) ; 
      }      
    }  
   class MyComparer implements Comparator  {  
     public int compare ( Object obj1, Object obj2 )  
      {  
       return  (    ( String ) obj2  ) .compareTo (  ( String ) obj1 ) ; 
      }  
    }  
   /** 
    * @param args 
    */
 
   public static void main ( String [  ]  args )   {  
     // TODO Auto-generated method stub 
     TestPart1 t = new TestPart1 (  ) ; 
     t.testLoop (  ) ; 
    }  
  } 


public static void sort(long[] a)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1804]java: add elements in array into list
By sri on 2006/08/07 01:16:09  Rate
Hi everybody 
  
  
 I can view all values in arrays but need to merge it using collections. 
 Really appreciate any ideas. 
  
  
 **************************************************** 
 for  ( int i = 0; i  <  width; i++ )   {   
     for  ( int j = 0; j  <  height; j++ )   {   
  
  
 int  [  ]  I = new int  [ 10 ] ; 
 int  [  ]  J = new int  [ 10 ] ; 
  
  
 System.out.print ( "X : "  ) ; 
 System.out.println ( I [ i ]  +i  ) ; 
  
  
 System.out.print ( "Y : "  ) ; 
 System.out.println ( J [ j ]  +j  ) ; 
  
  
 List listx = new ArrayList (  ) ; 
 List listy = new ArrayList (  ) ; 
  
  
 ??? 
  
  
  
 -sri- 
 


public static void sort(long[] a,
                        int fromIndex,
                        int toIndex)
See Also:
ArrayIndexOutOfBoundsException, IllegalArgumentException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void sort(short[] a)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void sort(short[] a,
                        int fromIndex,
                        int toIndex)
See Also:
ArrayIndexOutOfBoundsException, IllegalArgumentException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static <T> void sort(T[] a,
                            int fromIndex,
                            int toIndex,
                            Comparator<? super T> c)
See Also:
ArrayIndexOutOfBoundsException, IllegalArgumentException, ClassCastException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static <T> void sort(T[] a,
                            Comparator<? super T> c)
See Also:
ClassCastException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static String toString(boolean[] a)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static String toString(byte[] a)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static String toString(char[] a)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static String toString(double[] a)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static String toString(float[] a)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static String toString(int[] a)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static String toString(Object[] a)
See Also:
deepToString(Object[]), Object.toString()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static String toString(long[] a)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static String toString(short[] a)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  

Popular Tags