判断列表中值是否都相等 package com.fast.algorithm;import java.util.ArrayList;import java.util.List;/** *判断列表中值是否都相等 * * @author lushuifa242 * */public class RepeatList {public static void main(String[] args)
package com.fast.algorithm; import java.util.ArrayList; import java.util.List; /** *判断列表中值是否都相等 * * @author lushuifa242 * */ public class RepeatList { public static void main(String[] args) { Listlist = new ArrayList (); list.add(10); list.add(10); list.add(10); list.add(12); list.add(10); boolean actionFlag = checkListAllRepeat(list); System.out.println(actionFlag); } /** * 判断列表中值是否都相等 * @param list * @return true代表都相等,false代表存在不相等 */ private static boolean checkListAllRepeat(List list) { boolean flag = true; for (int i = 0; i < list.size(); i++) { int startV = list.get(i); if(i+1!=list.size()){ int endV = list.get(i+1); flag = startV==endV; System.out.println("对比的上第【"+i+"】和第【"+(i+1)+"】对比结果为:"+flag); if(!flag){ break; } } } return flag; } }