How to convert String[] to String and vice versa in Android

Christine

I want to convert a String Array to String so that later on while retrieving I can parse String to String[] with the help of (,) separator.

String [] ------------> String
//and later
String ---------------> String[]

Can someone guide on how to do this?

for (int i = 0; i <= count; i++) {

Log.d(TAG, "arrayData == " +arrayData[i]);

    // Joining:
    String joined = String.join(",", arrayData);
    //This will give error "The method join(String, String[]) is undefined for the type String"
}
Unihedron

You can use String.join StringBuilder and String.split:

// Joining:
String joined = String.join(",", stringArr);
StringBuilder buffer = new StringBuilder();
for (String each : stringArr)
  buffer.append(",").append(each);
String joined = buffer.deleteCharAt(0).toString();

// Splitting:
String[] splitted = joined.split(",");

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to convert a netty ByteBuf to a String and vice versa

How to convert numpy array to string and vice versa

how to convert joda datetime to String and vice versa

How to convert byte array to string and vice versa?

How to convert a string to hex and vice versa in c?

How to convert string variable to int and vice versa in CLASSIC ASP

How to convert WCHAR* to string in C++ and vice versa?

How many ways to convert bitmap to string and vice-versa?

How do you convert a byte array to a hexadecimal string, and vice versa?

How to convert double byte character/string to single byte and vice versa?

How to convert string into numpy array for tensorflow and vice versa

Convert List<int> to string and vice versa?

Python convert set to string and vice versa

Convert an IP string to a number and vice versa

convert string to json in golang and vice versa?

Convert string time to unix time and vice versa

Convert a Guid string into BigInteger and vice versa

Android-Java List to String and vice versa

String to QR Code and vice versa in Android Studio

How to convert Drawable into int and vice versa in Android

byte to string and vice versa

How to convert characters of a string from lowercase to upper case and vice versa without using string functions in python?

How to convert 8-char string to a 64-bit bigint and vice versa?

How to convert an integer to a c-string and vice versa and other datatypes without using any in-built functions?

Convert ObjectId to String and vice versa inside MongoDB aggregate map

Convert dataset to xml string with nested repeated xml vice versa

Java: Can I convert List of Object to List of String[] and vice versa?

Cannot convert String to byte array and vice versa in Java

Convert hour minute string time to utc and vice versa