论java中的contains

Arrays中常用的几个静态方法:

1、二分查找,是静态方法,且不需排序,返回下标。

static int binarySearch(byte[] a, byte key)
Searches the specified array of bytes for the specified value using the binary search algorithm.
   
static int binarySearch(char[] a, char key)
Searches the specified array of chars for the specified value using the binary search algorithm.
   
static int binarySearch(double[] a, double key)
Searches the specified array of doubles for the specified value using the binary search algorithm.
   
static int binarySearch(float[] a, float key)
Searches the specified array of floats for the specified value using the binary search algorithm.
   
static int binarySearch(int[] a, int key)
Searches the specified array of ints for the specified value using the binary search algorithm.
   
   
static int binarySearch(long[] a, long key)
Searches the specified array of longs for the specified value using the binary search algorithm.
   
static int binarySearch(Object[] a, Object key)
Searches the specified array for the specified object using the binary search algorithm.
static int binarySearch(short[] a, int fromIndex, int toIndex, short key)
Searches a range of the specified array of shorts for the specified value using the binary search algorithm.
static int binarySearch(short[] a, short key)
Searches the specified array of shorts for the specified value using the binary search algorithm.
   

2、复制数组,静态方法;

static boolean[] copyOf(boolean[] original, int newLength)
Copies the specified array, truncating or padding with  false (if necessary) so the copy has the specified length.
static byte[] copyOf(byte[] original, int newLength)
Copies the specified array, truncating or padding with zeros (if necessary) so the copy has the specified length.
static char[] copyOf(char[] original, int newLength)
Copies the specified array, truncating or padding with null characters (if necessary) so the copy has the specified length.
static double[] copyOf(double[] original, int newLength)
Copies the specified array, truncating or padding with zeros (if necessary) so the copy has the specified length.
static float[] copyOf(float[] original, int newLength)
Copies the specified array, truncating or padding with zeros (if necessary) so the copy has the specified length.
static int[] copyOf(int[] original, int newLength)
Copies the specified array, truncating or padding with zeros (if necessary) so the copy has the specified length.
static long[] copyOf(long[] original, int newLength)
Copies the specified array, truncating or padding with zeros (if necessary) so the copy has the specified length.
static short[] copyOf(short[] original, int newLength)
Copies the specified array, truncating or padding with zeros (if necessary) so the copy has the specified length.
static <T> T[] copyOf(T[] original, int newLength)
Copies the specified array, truncating or padding with nulls (if necessary) so the copy has the specified length.
static <T,U> T[] copyOf(U[] original, int newLength, Class<? extends T[]> newType)
Copies the specified array, truncating or padding with nulls (if necessary) so the copy has the specified length.
3、判断是否相等,静态方法;

static boolean equals(boolean[] a, boolean[] a2)
Returns  true if the two specified arrays of booleans are  equal to one another.
static boolean equals(byte[] a, byte[] a2)
Returns  true if the two specified arrays of bytes are  equal to one another.
static boolean equals(char[] a, char[] a2)
Returns  true if the two specified arrays of chars are  equal to one another.
static boolean equals(double[] a, double[] a2)
Returns  true if the two specified arrays of doubles are  equal to one another.
static boolean equals(float[] a, float[] a2)
Returns  true if the two specified arrays of floats are  equal to one another.
static boolean equals(int[] a, int[] a2)
Returns  true if the two specified arrays of ints are  equal to one another.
static boolean equals(long[] a, long[] a2)
Returns  true if the two specified arrays of longs are  equal to one another.
static boolean equals(Object[] a, Object[] a2)
Returns  true if the two specified arrays of Objects are  equal to one another.
static boolean equals(short[] a, short[] a2)
Returns  true if the two specified arrays of shorts are  equal to one another.
static void fill(boolean[] a, boolean val)
Assigns the specified boolean value to each element of the specified array of booleans.
4、排序,静态方法,返回的是void类型;

static void sort(byte[] a)
Sorts the specified array into ascending numerical order.
static void sort(byte[] a, int fromIndex, int toIndex)
Sorts the specified range of the array into ascending order.
static void sort(char[] a)
Sorts the specified array into ascending numerical order.
static void sort(char[] a, int fromIndex, int toIndex)
Sorts the specified range of the array into ascending order.
static void sort(double[] a)
Sorts the specified array into ascending numerical order.
static void sort(double[] a, int fromIndex, int toIndex)
Sorts the specified range of the array into ascending order.
static void sort(float[] a)
Sorts the specified array into ascending numerical order.
static void sort(float[] a, int fromIndex, int toIndex)
Sorts the specified range of the array into ascending order.
static void sort(int[] a)
Sorts the specified array into ascending numerical order.
static void sort(int[] a, int fromIndex, int toIndex)
Sorts the specified range of the array into ascending order.
static void sort(long[] a)
Sorts the specified array into ascending numerical order.
static void sort(long[] a, int fromIndex, int toIndex)
Sorts the specified range of the array into ascending order.
static void sort(Object[] a)
Sorts the specified array of objects into ascending order, according to the  natural ordering of its elements.
static void sort(Object[] a, int fromIndex, int toIndex)
Sorts the specified range of the specified array of objects into ascending order, according to the  natural ordering of its elements.
static void sort(short[] a)
Sorts the specified array into ascending numerical order.
static void sort(short[] a, int fromIndex, int toIndex)
Sorts the specified range of the array into ascending order.
5、转换为String类型;

static String toString(boolean[] a)
Returns a string representation of the contents of the specified array.
static String toString(byte[] a)
Returns a string representation of the contents of the specified array.
static String toString(char[] a)
Returns a string representation of the contents of the specified array.
static String toString(double[] a)
Returns a string representation of the contents of the specified array.
static String toString(float[] a)
Returns a string representation of the contents of the specified array.
static String toString(int[] a)
Returns a string representation of the contents of the specified array.
static String toString(long[] a)
Returns a string representation of the contents of the specified array.
static String toString(Object[] a)
Returns a string representation of the contents of the specified array.
static String toString(short[] a)
Returns a string representation of the contents of the specified array.
6、转换为list;

String[] stringArray = { "a","b", "c", "d", "e" };

ArrayList<String> arrayList = new ArrayList<String>(Arrays.asList(stringArray));

System.out.println(arrayList);

注意:

Integer[] data= new Integer[] {1,2,3};
ArrayList<Integer>  dataList  =new ArrayList<Integer>(Arrays.asList(data));

要想把数组转化为List,数组应该是类类型数组,基本数据构成的数组不行。还有就是Arrays.asList(data)返回的是List因此最好是使用上面的形式。

7、数组中没有contains方法;

8、String中有contains方法;是对象的方法。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值