Norm Radder wrote:The print statement on line 5 prints the contents of the variable: output
The contents of the variable: output was set on line 2 and not changed after that.
What was the contents of the variable: value when line 2 was executed? That was put into the contents of the variable: output
Carey Brown wrote: This has nothing to do with String being immutable. It has to do with the order that statements are processed. On line 2 you set the variable "output" and you don't reset the variable after that so that is what is printed.
This will print "0" as well. For the same reason.
Piet Souris wrote:Given that you must deal with synonyms, a Map<String, List<Word>> seems more reasonable.
With the toMap, it means that when we have two equal Strings, we need to put the two associated Words into a List. Now, that is not so easy to accomplish with the toMap method, but the alternative mappng method is in this case very much easier. I'm talking about the Collectors.groupingBy method. See the API of the Collectors class; we can use the simplest version, only specifying the key. So we get:
Piet Souris wrote:hi Mike,
for the toMap you need two mappers, one that maps the element to a key, and one that maps the element to a value (and if there is a possibility of having non unique keys, a BiFunction that tells what to do with the values in that case). You already have the key mapper, you need a value mapper. So the second argument would be: word -> word, or somewhat more stylish: Function.identity().
In that last case: why does the method reference: Function::identity not work?
Rob Spoor wrote:For Twitter there is even a library you can use: http://twitter4j.org/en/. I've used this in the past for just this purpose. Just keep the rate limiting in mind.
Rob Spoor wrote:You don't need @RequestBody, only @RequestParam. Unlike JAX-RS (which uses @QueryParam), this does not only check for query parameters but all request parameters. If it can be returned by ServletRequest.getParameter it can be injected as @RequestParam. An example:
Note that these parameters are all required; to make them optional you need to explicitly state this (and use either the value or name annotation property). You can also define default values:
See https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/bind/annotation/RequestParam.html for more information.
Rob Spoor wrote:If you can't use 4 method parameters all annotated with @RequestParameter, you can always have the HttpServletRequest as a method parameter and query its parameters.