Janishar Ali
Jul 23, 2017 · 1 min read

Vladimir Chernis A buffer is a temporary reusable space managed by a program for the purpose of making the data stream efficient. We can understand buffering process by an excellent analogy I found at StackOverflow.

Imagine that you’re eating candy out of a bowl. You take one piece regularly. To prevent the bowl from running out, someone might refill the bowl before it gets empty, so that when you want to take another piece, there’s candy in the bowl.

The bowl acts as a buffer between you and the candy bag.

Let’s puts a test on an Observable

List<Integer> data = Arrays.asList(1, 2, 3, 4);

Observable stream = Observable.fromIterable(data);

stream.subscribe(
val -> System.out.print(val + " "),
err -> System.out.println("\nerror " + err),
() -> {
System.out.println("\ncompleted");
data.set(0, 5);
data.set(1, 6);
data.set(2, 7);
data.set(3, 8);
stream.subscribe(
val -> System.out.print(val + " "),
err -> {
System.out.println("\nerror ");
},
() -> System.out.println("\ncompleted"));
});

Output:

1 2 3 4
completed
5 6 7 8
completed

If we modify the items of the data the publisher sends the new items meaning that it is not storing the information in a buffer.

    Janishar Ali

    Written by

    IIT | Co-Founder @ MindOrks | Building AfterAcademy | Code.all() | Disrupting EdTech | #MakeEveryoneCode | Now I only write at https://blog.mindorks.com

    Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
    Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
    Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade