0

I want to print at a time of ArrayList.

Before:

class ExampleUnitTest {
    @Test
    fun test(){
        val stringArray = arrayOf("10", "20", "30", "40", "30", "20", "10", "5", "20", "30", "20", "30").map { it }
        println(stringArray.toString())
    }
}

# output is :
[10, 20, 30, 40, 30, 20, 10, 5, 20, 30, 20, 30]

After:

# I Want to output Like this :
10, 20, 30, 40, 30, 20, 10, 5, 20, 30, 20, 30

How can I do this coding by Reactivex Java(RxJava)

# something like... e.g..
Observable ...{
   ... ...
}.subscribeOn(Schedulers.io())
.subscribe({
   ... ...
})
un Lim
  • 75
  • 1
  • 7

2 Answers2

0

i got finished the problem by my self!

val sample = listOf("a","b","c","d","e","f","g")
        Observable.fromIterable(sample.withIndex())
            .subscribeOn(Schedulers.io())
            .subscribe({ (index, item) ->
                print(if(sample.size > index) item else "$item, ")
                println()
            },
            { e -> e.printStackTrace() },
            { println("finished!") }
        )
un Lim
  • 75
  • 1
  • 7
0

You can use fromArray opearator and some string inbuilt funcation

      val stringArray = arrayOf("10", "20", "30", "40", "30", "20", "10", "5", "20", "30", "20", "30")

        Observable.fromArray(stringArray).map {
            Arrays.toString(it).replace("[","").replace("]","")
        } .subscribe(
            {
//               Desired OP: 10, 20, 30, 40, 30, 20, 10, 5, 20, 30, 20, 30
                Log.d("test"," $it")
            }
        )
rawhost
  • 144
  • 1
  • 6