java实现二维数组排序并定位坐标(借助list)
来源:互联网 发布:网络上hx是什么意思 编辑:程序博客网 时间:2024/06/06 17:52
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Comparator;
public class test {
static class one{
private int x;
private int y;
private int count;
private int xxx;
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public one(int x, int y, int count,int xxx) {
super();
this.x = x;
this.y = y;
this.count = count;
this.setXxx(xxx);}
public int getXxx() {
return xxx;
}
public void setXxx(int xxx) {
this.xxx = xxx;
}
}
public static void main(String[] args) {
int [][]a=
{
{1,3,2},
{5,5,5},
{4,7,8}
};
int [][]b={
{2,4,5},
{1,6,9},
{8,4,10}
};
List<one> list=new ArrayList<one>();
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a[i].length; j++) {
one o=new one(i,j,a[i][j],b[i][j]);
list.add(o);
}
}
Collections.sort(list, new Comparator<one>(){
public int compare(one o1, one o2) {
if(o1.getCount()< o2.getCount()){
return 1;
}
if(o1.getCount()== o2.getCount()){
if(o1.getXxx()<o2.getXxx())
return 1;
if(o1.getXxx()==o2.getXxx())
return 0;
return -1;
}
return -1;
}
});
for (int i = 0; i < list.size(); i++) {
System.out.println(list.get(i).getX()+"--"+list.get(i).getY());
System.out.println(list.get(i).getCount());
}
}
}
import java.util.Collections;
import java.util.List;
import java.util.Comparator;
public class test {
static class one{
private int x;
private int y;
private int count;
private int xxx;
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public one(int x, int y, int count,int xxx) {
super();
this.x = x;
this.y = y;
this.count = count;
this.setXxx(xxx);}
public int getXxx() {
return xxx;
}
public void setXxx(int xxx) {
this.xxx = xxx;
}
}
public static void main(String[] args) {
int [][]a=
{
{1,3,2},
{5,5,5},
{4,7,8}
};
int [][]b={
{2,4,5},
{1,6,9},
{8,4,10}
};
List<one> list=new ArrayList<one>();
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a[i].length; j++) {
one o=new one(i,j,a[i][j],b[i][j]);
list.add(o);
}
}
Collections.sort(list, new Comparator<one>(){
public int compare(one o1, one o2) {
if(o1.getCount()< o2.getCount()){
return 1;
}
if(o1.getCount()== o2.getCount()){
if(o1.getXxx()<o2.getXxx())
return 1;
if(o1.getXxx()==o2.getXxx())
return 0;
return -1;
}
return -1;
}
});
for (int i = 0; i < list.size(); i++) {
System.out.println(list.get(i).getX()+"--"+list.get(i).getY());
System.out.println(list.get(i).getCount());
}
}
}
1 0
- java实现二维数组排序并定位坐标(借助list)
- Java实现二维数组排序(先行再列)
- Java代码实现二维数组的排序
- 实现二维数组排序
- java二维数组排序
- JAVA冒泡排序实现(Object数组、List容器)
- Java中的利用List实现数组排序
- Java,List生成二维数组
- java list转二维数组
- php二维数组排序实现
- Java 实现二维数组按指定列经行排序
- Java 实现二维数组按指定列经行排序
- java中二维数组排序
- Java二维数组冒泡排序
- java二维数组冒泡排序
- 二维坐标排序
- 二维数组中的查找(java实现)
- 不借助二维数组,输出蛇形数组
- mysql处理字符串的两个绝招:substring_index,concat
- Ubuntu 16.04安装Eclipse
- WOJ 26 Lost in WHU(矩阵快速幂+邻接矩阵乘法)
- 面试题
- Ecshop模板开发(十五):商品详情页购买过该商品的人还购买了
- java实现二维数组排序并定位坐标(借助list)
- QT5简易音乐播放器的设计
- jQuery事件之鼠标事件
- 编程题(4):人人网
- 1
- JSON学习笔记
- 2
- android studio创建activity时在清单文件自动加上 android:screenOrientation="portrait"
- 抽象类和接口的区别