"combinatoricslib"을 사용하여 객체 배열에서 조합을 생성했습니다. 그러나 결과는 벡터로 표시됩니다. 하나의 값만 읽는 법을 알고 싶습니다.자바에서 벡터를 읽는 방법
다음은 코드입니다.
// Create the initial vector
ICombinatoricsVector<String> initialVector = Factory.createVector(
new String[] { "red", "black", "white", "green", "blue" });
// Create a simple combination generator to generate 3-combinations of the initial vector
Generator<String> gen = Factory.createSimpleCombinationGenerator(initialVector, 3);
// Print all possible combinations
for (ICombinatoricsVector<String> combination : gen) {
System.out.println(combination);
}
결과입니다.
CombinatoricsVector=([red, black, white], size=3)
CombinatoricsVector=([red, black, green], size=3)
CombinatoricsVector=([red, black, blue], size=3)
CombinatoricsVector=([red, white, green], size=3)
CombinatoricsVector=([red, white, blue], size=3)
CombinatoricsVector=([red, green, blue], size=3)
CombinatoricsVector=([black, white, green], size=3)
CombinatoricsVector=([black, white, blue], size=3)
CombinatoricsVector=([black, green, blue], size=3)
CombinatoricsVector=([white, green, blue], size=3)
그러나 조합 배열과 크기를 모두 가지고 있습니다. 하지만 배열 만 가져오고 싶습니다. 그것을 얻는 방법. 도와주세요. 나는 자바를 처음 사용합니다.
미리 감사드립니다.
고마워요. 그것은 효과가 있었다. – Daybreaker