赞
踩
public static void main(String[] args) {
text(); //0
text(1,2,3);//3 1 2 3
text(new int[]{20,30,40,50});//4 20,30,40,50
}
public static void text(int...nums){
System.out.println(nums.length);
for (int i = 0; i < nums.length; i++) {
System.out.print(nums[i]+" ");
}
System.out.println();
}
操作集合的工具类
常用方法:
List<Integer> list=new ArrayList<>(); //为集合加入一批数据 Collections.addAll(list,1,2,5,4); System.out.println(list);//[1, 2, 5, 4] //打乱集合中的数据 Collections.shuffle(list); System.out.println(list);//[4, 2, 5, 1] //排序 Collections.sort(list); System.out.println(list);//[1, 2, 4, 5] //如果是为 一个类排序 则需要该类继承Comparable<> 并重写其中的方法 //或者使用 sort Collections.sort(list, new Comparator<Integer>() { @Override public int compare(Integer o1, Integer o2) { return o1-o2; } }); System.out.println(list);//[1, 2, 4, 5]
Card类
:
package com.cky.Collecting; public class Card { private String number; //牌数字 private String color; //排颜色 private int size; //牌大小 public Card(String number, String color, int size) { this.number = number; this.color = color; this.size = size; } public Card() { } @Override public String toString() { return color+number; } public String getNumber() { return number; } public void setNumber(String number) { this.number = number; } public String getColor() { return color; } public void setColor(String color) { this.color = color; } public int getSize() { return size; } public void setSize(int size) { this.size = size; } }
Room类
:
package com.cky.Collecting;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class Room {
//必须要有一副牌
public List<Card> Allcards=new ArrayList<>();
public Room(){
String[] numbers={String[] numbers={"3","4","5","6","7","8","9","10","J","Q","K","A","2"};};
String[] colors={"♦","❤","声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/251640
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。