본문 바로가기

Android/일반

안드로이드/Android ArrayList "0" 문자열 포지션 찾기

안드로이드/Android ArrayList "0" 문자열 포지션 찾기
 
private int getType(ArrayList arrays){
		int result = 0;
		int[] num = new int [3];

		for(int i=0 ; i<arrays.size() ; i++ ){
			if(arrays.get(i).contains("0")){
				if(i<=7){
					num[0]++;
				}else if(i>=8&&i<=13){
					num[1]++;
				}else if(i>=14&&i<=19){
					num[2]++;
				}
			}
		}

		int max = num[0];
		ArrayList position = new ArrayList();

		for (int i = 0; i < 3; i++) {
			if (num[i] >= max) {
				if (num[i] == max) {
					position.add(i);
				} else {
					max = num[i];
					position.clear();
					position.add(i);
				}
			}
		}
		
		for(int i=0 ; i<num.length ; i++){
			Logger.d(TAG, "num["+i+"] = " + num[i]);
		}

		for(int i : position){
			Logger.d(TAG, "i = " + i);
		}

		Logger.d(TAG, "max = " + max);

		if(position.size()>=0){
			int randomPosition = (int) (Math.random() * position.size());
			Logger.i(TAG, "randomPosition : " + randomPosition);
			//----------------------
			Logger.i(TAG, "position.get(randomPosition) : " + 
                        position.get(randomPosition));
			//----------------------
			Logger.i(TAG, "num[position.get(randomPosition)] : " + 
                        num[position.get(randomPosition)]);
			
			result = position.get(randomPosition);
		}
			
		return result;
	}