user2908626 user2908626 - 26 days ago 4
Java Question

How convert table into string?

I want to convert table into one string:

int y [] = {30, 34, 45, 57, 77, 89, 100, 111, 123, 145};


Must be something as this:

String y = 30, 34, 45, 57, 77, 89, 100, 111, 123, 145;


Far code:

public class GraphLoading extends Activity {
public static int [] y;
int Test;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.loading);




int y [] = {30, 34, 45, 57, 77, 89, 100, 111, 123, 145};



}

public static int[] x = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

}


I must convert that tablo into string then I can save it into SD card.

Please can you paste full code? (I am amateur)

Answer

You can rely on the implementation of Arrays.toString:

String y1 = Arrays.toString(y).replaceAll("\\[|\\]", "");

Otherwise you can loop through your int array and append each element using a StringBuilder.