
Java
java基础
afreshhand
这个作者很懒,什么都没留下…
展开
-
stream流简单用法总结
List<Integer> numList = Arrays.asList(1,2,5,10); //方法一: int max = numList.stream().mapToInt(x -> x).summaryStatistics().getMax(); int min = numList.stream().mapToInt(x -> x).summaryStatistics().getMin(); doubl...原创 2022-04-06 13:23:29 · 4960 阅读 · 1 评论 -
java list集合转字符串,以逗号分割
import org.apache.commons.lang3.StringUtils; public static void main(String[] args) { List<String> list = new ArrayList<>(); list.add("1"); list.add("2"); list.add("3"); String str = StringUtils.joi.原创 2021-12-15 11:03:58 · 882 阅读 · 0 评论 -
Java基本数据类型、包装类、String类之间的相互转换
1.基本数据类型和包装类之间可以自动转换2.基本数据类型转String类,调用String类的valueOf()方法String类转基本数据类型,调用基本数据类型相应的包装类的parseXxx(String)静态方法3.String类转包装类, 包装类转String类,调用包装类对象的toString()方法...原创 2021-10-24 15:41:18 · 217 阅读 · 0 评论 -
java重写compareTo()方法,比较对象的大小
package com.example.demo;/** * 商品类 */public class Goods implements Comparable{ private String name; private double price; public Goods() { } public Goods(String name, double price) { this.name = name; this.price.原创 2021-10-13 16:35:25 · 12309 阅读 · 0 评论 -
快速入门Java面向对象之包装类
基本数据类型和包装类之间的转换什么是包装类在JAVA中,八大基础数据类型(int,float,double...)是不具备对象的特征的,比如基本数据类型就不能调用方法,功能简单,为了让基本数据类型也具备对象的特征,就有了JAVA包装类。包装类就是:将基本数据类型包装成对象,使其具有了对象的属性和方法。而包装类的主要作用也就是:将本类型与其他类型进行转换; 将字符串与本类型...原创 2020-04-20 21:14:08 · 228 阅读 · 0 评论 -
选择排序法实现数组排序
import java.util.*;public class Sort { public static void main(String[] args) { Scanner sc = new Scanner(System.in); // 动态创建数组 int[] arr = new int[sc.nextInt()]; for (int i = 0; i < arr.l...原创 2020-03-17 20:26:42 · 763 阅读 · 0 评论 -
java实现n×n数组的行列互换
public class Test { public static int[][] swapRowColumn(int[][] arr) { int[][] arr2 = new int[arr.length][arr.length]; for (int i = 0; i < arr2.length; i++) { // 调整数组行列数据 for (int j = 0; j ...原创 2020-03-11 19:13:06 · 1671 阅读 · 0 评论 -
java求一个数的阶乘
import java.util.*;public class Test04 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("请输入一个自然数N:"); int N = sc.nextInt(); int sum = 1; ...原创 2020-02-27 09:55:17 · 824 阅读 · 0 评论 -
java打印99乘法表
public class Test05 { public static void main(String[] args) { for (int i = 1; i <= 9; i++) { for (int j = 1; j <= i; j++) { System.out.print(j + "*" + i + "=" + j * i + "\t"); } ...原创 2020-02-27 09:16:47 · 211 阅读 · 0 评论 -
Java用for循环打印正三角形和倒三角形
public class Test05 { public static void main(String[] args) { // 在这里打印出正三角形 for (int i = 1; i <= 10; i++) { for (int j = 1; j <= i; j++) { System.out.print("*"); } System.out....原创 2020-02-26 21:52:43 · 6743 阅读 · 2 评论 -
java实现输入一个字符串,统计数字的个数
import java.util.*;public class Test02 { public static void main(String[] args) { Scanner scan=new Scanner(System.in); String info=scan.next(); int index=0; int c...原创 2020-02-24 21:00:04 · 4397 阅读 · 0 评论 -
冒泡法实现数组排序
冒泡法排序public static void main(String[] args) { int arr[]={1,5,3,2,9}; for(int i=0;i<arr.length-1;i++){ for(int j=i+1;j<arr.length;j++){ if (arr[j]<arr[i]){ int temp=arr[i]; ar...原创 2020-03-21 11:15:06 · 195 阅读 · 0 评论