判断该list集合里面是否有连续的数字
2017-10-27 14:51
357 查看
// 参数 ,List集合:想要查找连续数字的集合,max:想要找几个连续数字
// 返回值:返回删除连续数字之后的集合,(要是想要获取连续序列的集合可以自行修改返回值就是多个LIst<Integer> seq )
private List<Integer> isSequence(List<Integer> pokers, int max) {
Collections.sort(pokers); // 先将集合中的元素排序
if(CollectionUtils.isNotEmpty(pokers) && pokers.size() >= max){
for(int index = 0; index < pokers.size(); index++){
List<Integer> seq = new ArrayList<>(max);
int currValue = pokers.get(index);
for(int j = currValue; j < currValue + max; j ++){
if(pokers.contains(j)){ // 判断当前元素的下一个是否在list集合里面如果存在将 为true存在map里
seq.add(j); // 将连续的存在seq中
}
}
if(seq.size() == max){
for(Integer num : seq){
pokers.remove(pokers.indexOf(num)); // 根据元素的索引位置删除元素 , 只想删除一个元素seq对应的一个元素,并且不删除重复元素的时候,
// 我使用的是poker.remove(int index) 根据索引删除(
注释:1,不可以直接使用pokers.remove(Object o) 这个方法,会发生数组越界,
2,也不可以使用removeAll(Collenction<T> c)
举例:List<Integer> a = new ArrayList<>(Array.asList(new Integer(1,2,3,4,5,6,7,1,1,1)));
List<Integer> b = new ArrayList<>(Array.asList(new Integer(1)));
用a.removeAll(b),就会把集合a里面的所有的元素1,都会删除。
}
}
}
}
return pokers;
}
// 返回值:返回删除连续数字之后的集合,(要是想要获取连续序列的集合可以自行修改返回值就是多个LIst<Integer> seq )
private List<Integer> isSequence(List<Integer> pokers, int max) {
Collections.sort(pokers); // 先将集合中的元素排序
if(CollectionUtils.isNotEmpty(pokers) && pokers.size() >= max){
for(int index = 0; index < pokers.size(); index++){
List<Integer> seq = new ArrayList<>(max);
int currValue = pokers.get(index);
for(int j = currValue; j < currValue + max; j ++){
if(pokers.contains(j)){ // 判断当前元素的下一个是否在list集合里面如果存在将 为true存在map里
seq.add(j); // 将连续的存在seq中
}
}
if(seq.size() == max){
for(Integer num : seq){
pokers.remove(pokers.indexOf(num)); // 根据元素的索引位置删除元素 , 只想删除一个元素seq对应的一个元素,并且不删除重复元素的时候,
// 我使用的是poker.remove(int index) 根据索引删除(
注释:1,不可以直接使用pokers.remove(Object o) 这个方法,会发生数组越界,
2,也不可以使用removeAll(Collenction<T> c)
举例:List<Integer> a = new ArrayList<>(Array.asList(new Integer(1,2,3,4,5,6,7,1,1,1)));
List<Integer> b = new ArrayList<>(Array.asList(new Integer(1)));
用a.removeAll(b),就会把集合a里面的所有的元素1,都会删除。
}
}
}
}
return pokers;
}
相关文章推荐
- JSTL判断一个list集合里是否包含某个字符串
- 判断CString里面的字符串是否全为数字构成
- 集合(list)判断是否存在对应的字符串或对象
- 根据2个条件判断集合里面是否存在元素,用拉姆达表达式
- 通过参数传递,判断数字、字符串、list、tuple、词典等数据类型是否为可变数据对象。
- 给一串数字,判断是否连续
- @V@ java代码笔记2010-06-12:java控制台输入各类型类实现;以及判断输入字符串里面是否有数字的两种方法:方法1:转换成字符数组;方法2:正则表达式。
- 怎么判断List集合是否为空?
- ASP.NET 判断是否是连续的数字(可重复,但必须是连续的数字)
- poj 3630 Phone List 【字典树】【判断一个字符串集里面 是否存在一个字符串是另一个字符串前缀】
- C# 判断两个集合(List)是否相等
- Java判断一个值,或者对象是否存在list集合中和去掉list集合中重复的元素
- Map 集合里 判断里面参数是否存在 hibernate String时间查询
- 判断数字是否可有连续数字和组成
- 输入5个数字,如果数组中有0则0可以替代任何数字,判断该数组中的数字是否是连续数字。
- 判断是否是连续数字
- java中判断集合list是否为空
- 判断是否为连续的数字拼接而成的字符串
- 通过参数传递,判断数字、字符串、list、tuple、词典等数据类型是否为可变数据对象。
- js里面判断是否为数字的方法