How to assign StringBuilder to String value at Android?

I have a dynamic message Stringbuilder value in my codes. But i want to create temp string and i want to save message value to temp value and than clean message value: For example:

StringBuilder messages;
StringBuilder [] temp = new StringBuilder[1000];
...///other part of codes
temp[i]=message;
 String text=intent.getStringExtra("theMessage");
i++;
 messages.delete(0, messages.length());

A mean, when my messages come 34 i want to save temp[0] and clean message and i want to increase i with i++ and than message come 23 than temp[1]=23 and so on... How can i do this at android ?

1 answer

  • answered 2018-07-11 05:57 Sagar

    Its as simple as following:

        StringBuilder [] temp = new StringBuilder[1000];
        int index = 0;
        if(messages.length() == 34){
            temp[index] = new StringBuilder(messages);
            messages.delete(0, messages.length());
        }
    
        ...
    

    If temp[] is of type String then simply

    temp[index] = new StringBuilder(messages.toString())