android - int array [] into set text

Viewed 369

How can I put my result array values into the text box "Test TextView" here?

I'm sosososo new to JAVA, so it would be really appreciated if you explain me too. Looking forward to get a nice answer!

public static void main(String args[]) {

    ArrayList<Integer> lottoNum = new ArrayList<Integer>();

    for (int i=1; i<=45; i++) {
        lottoNum.add(i);
    }
    Collections.shuffle(lottoNum);
    int[] lottoNums = new int[6];
    for (int i = 0; i <6; i++){
        lottoNums[i] = lottoNum.get(i);
        String s = java.util.Arrays.toString(lottoNums);
    }
}

I want to put the result of "lottoNums"

for example something like [11 28 55 32 66 77]

into the text box below.

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main2);

    TextView textView = findViewById(R.id.text_view);
    // テキストを設定して表示
    textView.setText("Test TextView");

This textView.setText() here.

1 Answers
int[] intArr = new int[] {
    1,
    2,
    3,
    4
};
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("[");
for (int i = 0; i < intArr.length; i++) {
    stringBuilder.append(intArr[i]).append(" ");


}
stringBuilder.replace(stringBuilder.length() - 1, stringBuilder.length() - 1, "]");
System.out.println(stringBuilder.toString());

How about appending all values and creating desired String

Related