aristas :
Quiero crear una cadena con String.Format como esto String.Format ( "Q1 = {}, {} = Q2, Q3 = {}, Q4 = {}" lista) a partir de los valores de una lista que contiene los números enteros.
private String createString(Player player){
List<Integer> answers= new ArrayList<>();
answers.add(player.getQuestion1());
answers.add(player.getQuestion2());
answers.add(player.getQuestion3());
answers.add(player.getQuestion4());
answers.add(player.getQuestion5());
answers.add(player.getQuestion6());
answers.add(player.getQuestion7());
answers.add(player.getQuestion8());
answers.add(player.getQuestion9());
answers.add(player.getQuestion10());
return String.format("Q1={}, Q2={}, Q3={}, Q4={}, Q5={}, Q6={}, Q7={}, Q8={}, Q9={}, Q10={}", answers.stream().map(a -> a.toString());
}
también:
Algo parecido a lo siguiente utilizando Collectors.joining
la cartografía como se requiere comunicaba con índice y respuesta:
return IntStream.range(0, answers.size())
.mapToObj(idx -> String.format("Q%s = %s", idx + 1, answers.get(idx)))
.collect(Collectors.joining(", "))