I have a table with 3 columns, like this
A|B|C
1|4|5
2|9|0
3|6|2
and so on...
I am creating this table using the data I am fetching from room database
Now I want to create a string that contains this data completely formatted like the table I have shown above. So that I can share the data as string through an intent. How can I accomplish this? I tried looking at other questions but they were using System.out.Format and i have no idea of how to use it store all that data in a string in an efficient way because my tables can have thousand of rows. I also tried searching on google with different queries on how to share the table data through intent in android.
I want to create a table like this.
https://stackoverflow.com/a/18672745
but I don't know how to save that output in a string so that I can share that using android intent.
this seemed to be the most related query to the problem to search
on google.
https://www.google.com/search?q=store+a+properly+formatted+table+in+a+string+java+android&client=opera&ei=21MCYYzCCsqW4-EPyaO5-A4&oq=store+a+properly+formatted+table+in+a+string+java+android&gs_lcp=Cgdnd3Mtd2l6EAMyBwghEAoQoAEyBwghEAoQoAE6BwgAEEcQsAM6BQghEKABOgQIIRAVSgQIQRgAUOGHB1illAdgnZYHaAFwAngAgAGRAogBvQ6SAQUwLjEuN5gBAKABAcgBCMABAQ&sclient=gws-wiz&ved=0ahUKEwjMm6yg3IfyAhVKyzgGHclRDu8Q4dUDCA4&uact=5
I am using a StringBuilder and iterating over each item in list using for loop the problem is that the format does not look good.
it looks like this
Number|column1|column2
1|0|0
2|0.602|2.674
3|0.5|3.174
builder.append("Number|"+"Column1"+"|Column2");
builder.append(System.getProperty("line.separator"));
for(int i=0;i<list.size();i++) {
if(i==0){
builder.append(i+"|" + "0"+"|0");
builder.append(System.getProperty("line.separator"));
} else {
...
}
}
and then builder.toString();