javaandroidstringcharsequence

Alternative to stream for converting Charsequence to String


I'm writing a mobile application in Android studio. I have an arrayList that i'm converting into a string to be evaluated in a script engine.

I am currently using

    resultText = total.stream().collect(Collectors.joining(""));

With total being

    ArrayList<CharSequence> total = new ArrayList<>();

The current input output is something like this

    CharSequence [1,+,2] --> .Stream() "1+2" --> .eval 3.0

Is there an alternative method to get this output? I'm currently using API level 28 to have access to stream, but i require a min API level of 19.

The .ToString() method does not get the required output.

    CharSequence [1,+,2] --> .ToString "[1,+,2]" --> .eval NULL

Any help would be greatly appreciated.


Solution

  • You can use TextUtils class.

    List<Character> list = new ArrayList<>(Arrays.asList(
            '1', '+', '2'
    ));
    
    String result = TextUtils.join("", list);
    

    Base od documentation method join() was Added in API level 1