No, "abc".concat("def") creates a new independent string altogether.
f.apply(vowels); returns only a view of the original list. It doesn't return an independent list. If you modify this list the original will get modified. This is explained in detail in the explanation with an example.
If you like our products and services, please help us by posting your review here.
Remember that, however, if you modify the sub list, the changes will be visible in the original list.
For example, the following will print aeioxu:
List<String> view = f.apply(vowels); //get a view backed by the original list
view.add("x"); //modify the view
vowels.forEach(System.out::print); //updates visible in original list
Why the output is aeioxu and not aeioux?
I think "add" method should add element at the end of the "view" list. Where is a mistake?
The answer is correct but the reason given is wrong
The answer is correct because apply returns the result of the function call and this result is discarded
The explanation addresses a mistaken belief that that list.subList(2, 4); modifies the list pointed to by list and the explanation is correct. f = list -> list.subList(2, 4); creates a new list with certain elements from the original list but doesn't modify the original list. This is true. The code prints the original list. And therefore, prints the same values that the original list had.
The explanation clearly says, "therefore, when you print the elements from the original list after calling subList". So, it says the same thing that you are saying. The code is not printing the new list.
Your code: vowels= f.apply(vowels); is entirely different. It doesn't not modify the original list either. It simply makes the vowel point to a new list.
In fact, your scenario is explained in the last part of the explanation where the new list is modifed but changes are also visible in the original list.
If you like our products and services, please help us by posting your review here.