java快速尋找一個數組的最大值或最小值, min, max,三種方法


		int[] prices = {7,1,5,3,6,4};
		//求出最大值的幾種方式
		int max = Arrays.stream(prices).max().getAsInt();
		System.out.println(max);
		int max1 = Collections.max(Arrays.asList(ArrayUtils.toObject(prices)));
		System.out.println(max1);
		
		Arrays.sort(prices);
		System.out.println(prices[prices.length - 1]);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM