码迷,mamicode.com
首页 >  
搜索关键字:Arrays    ( 3585个结果
JAVA中Arrays.sort()使用两种方式(Comparable和Comparator接口)对对象或者引用进行排序
一、描述 自定义的类要按照一定的方式进行排序,比如一个Person类要按照年龄进行从小到大排序,比如一个Student类要按照成绩进行由高到低排序。 这里我们采用两种方式,一种是使用Comparable接口:让待排序对象所在的类实现Comparable接口,并重写Comparable接口中的compareTo()方法,缺点是只能按照一种规则排序。 另一种方式是使用Comparator接口:编...
分类:编程语言   时间:2015-04-27 23:45:29    阅读次数:201
独立数组合的最大数
此接口强行对实现它的每个类的对象进行整体排序。这种排序被称为类的自然排序,类的compareTo方法被称为它的自然比较方法。实现此接口的对象列表(和数组)可以通过Collections.sort(和Arrays.sort)进行自动排序。实现此接口的对象可以用作有序映射中的键或有序集合中的元素,无需指...
分类:编程语言   时间:2015-04-27 23:26:04    阅读次数:158
求100到999之间水仙花的个数
题目:打印出所有的 水仙花数 ,所谓 水仙花数 是指一个三位数,其各位数字立方和等于该数本身。     例如:153是一个 水仙花数 ,因为153=1的三次方+5的三次方+3的三次方。 public static void main(String[] args) { System.out.println(Arrays.toString(getNarcissisticNumbe...
分类:其他好文   时间:2015-04-27 21:47:55    阅读次数:128
java8 函数式版 冒泡排序(BubbleSort)
package?com.doctor.algorithm.sort; import?java.util.Arrays; import?java.util.function.BiPredicate; /** ?*?java8?函数式版?冒泡排序(BubbleSort) ?*? ?*?@author?doctor ?* ?*?@time?2...
分类:编程语言   时间:2015-04-26 22:58:22    阅读次数:808
每天记点api(java)
java.lang.Comparable 1.0int compareTo(T other)//用这个对象与other进行比较。如果这个对象小于other则返回负值;如果相等则返回0;否则返回正值。java.util.Arrays 1.2static void sort(Object[] a)//使...
分类:编程语言   时间:2015-04-26 15:05:16    阅读次数:117
软件工程P37习题三程序代码
//软件工程作业P37第三题import java.util.Arrays;//假设传入的数组是{how,are,you}public class Test0001 {public void theExchangeOfWords(String[] a){for (int i = 0; i < a.l...
分类:其他好文   时间:2015-04-25 22:45:57    阅读次数:164
软件工程P37习题二程序代码
//软件工程作业P37第二题import java.util.Arrays;//假设传入的数组是{1,-2,3,-2,5,1}public class Test0000 {public void max(int[] a) {int b[] = new int[10];int c[] = new in...
分类:其他好文   时间:2015-04-25 22:45:09    阅读次数:123
java集合工具类---Collections/Arrays
/* *Collections用于操作List/Set的工具类 *Arrays用于操作数组的工具类 */ package pack;import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.Lis...
分类:编程语言   时间:2015-04-25 15:10:32    阅读次数:143
Java [leetcode 4] Median of Two Sorted Arrays
问题描述:There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexi...
分类:编程语言   时间:2015-04-25 15:04:09    阅读次数:133
Merge Sorted Array -- leetcode
Given two sorted integer arrays A and B, merge B into A as one sorted array. Note: You may assume that A has enough space (size that is greater or equal to m + n) to hold additional elements from ...
分类:其他好文   时间:2015-04-25 12:17:30    阅读次数:121
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!