Answer by Federico klez Culloca for Java map.copyOf not using source map...
The specification for the copyOf method statesReturns an unmodifiable Map containing the entries of the given Map.(emphasis mine)Which means only the entries get copied, nothing else. Hence, it is...
View ArticleAnswer by Federico klez Culloca for no instance(s) of type variable(s) K, V...
Map.of doesn't return a HashMap, it returns an unmodifiable map (what type that is exactly is implementation-dependent and not important), so you can't assign it to a HashMap.You can work around that...
View ArticleAnswer by Federico klez Culloca for TypeError: 'int' object is not...
The problem is that when evaluating player_cards[0][1][2][3][4] python would first evaluate player_cards[0] which is a number (let's suppose it's 4) and then try to do something like 4[1][2][3][4], so...
View ArticleAnswer by Federico klez Culloca for Problems with cli.get() and getting...
The Cliente class is empty (apart from an empty constructor that does nothing by itself if you don't tell it what to do). You have to define both the data it contains and the methods to get the data....
View ArticleAnswer by Federico klez Culloca for postfix evaluation calculated result is...
char token = expr.charAt(index); returns '3' on the first iteration, but that's a char representing the character '3' (i.e. 51), not the number 3.To use the number instead of the character representing...
View ArticleAnswer by Federico klez Culloca for Why there is no scanner.nextline() method...
nextInt reads the next token in the scanner.According to the documentationA Scanner breaks its input into tokens using a delimiter pattern, which by default matches whitespace.And further downThe...
View ArticleAnswer by Federico klez Culloca for Question about the behavior of toString...
According to the Java Language Specification:String contexts apply only to an operand of the binary + operator which is not a String when the other operand is a String.The target type in these contexts...
View ArticleAnswer by Federico klez Culloca for Terminal operations on streams cannot be...
BecauseAssuming you meant collect(Collectors.toList()), forEach is a List operation, not a Stream operation. Perhaps the source of your confusion: there is a forEach method on Stream as well, but...
View ArticleAnswer by Federico klez Culloca for Why does misusing 1 instead of 1.0 from...
In the first case a + a overflows to Integer.MIN_VALUE, then you switch to a double context with -1.0 which gives a negative number (Integer.MIN_VALUE - 1), since a double can hold a number smaller...
View ArticleAnswer by Federico klez Culloca for Printf in Java with variable spaces...
The format string is still a string, so assuming a width variable System.out.printf("%" + width +"d", x); does the trick.So for examplevar width = 10; var x = 123;System.out.printf("%" + width +"d",...
View ArticleAnswer by Federico klez Culloca for MapStruct : Setting value of now while...
You can use defaultExpression in your mapping. It expects a string as an argument, with the following format:"java(expression)"Where expression is the expression you're looking for, so in your...
View ArticleAnswer by Federico klez Culloca for Why is it not allowed to assign double...
Because an int fits inside a long, but if you put a double inside a float you may lose precision (it's a narrower type).If you really must you can force this via castingdouble d = 4.0;float f =...
View ArticleAnswer by Federico klez Culloca for What does %s(%s) specifier do?
By itself %s(%s) is simply two string placeholder one after the other, with the second being surrounded by parentheses that have no syntactic meaning as far as format is concerned.What this piece of...
View ArticleAnswer by Federico klez Culloca for How to convert minutes to Hours and...
If your time is in a variable called t :int hours = t / 60; // since both are ints, you get an intint minutes = t % 60;System.out.printf("%d:%02d", hours, minutes);It couldn't get easier.Addendum from...
View ArticleAnswer by Federico klez Culloca for when do we really benfit from java...
A per the documentation on stream ordering (emphasis mine):For parallel streams, relaxing the ordering constraint can sometimes enable more efficient execution. Certain aggregate operations, such as...
View ArticleAnswer by Federico klez Culloca for why override java's equals() method this...
Because if this == o it means that both this and o are actually the same object, so they are equal by definition and there's no need for further comparisons.
View ArticleAnswer by Federico klez Culloca for Java - print contents of a queue
How can I override the toString() method of Queue class to get the correct output ?You can't.For starters, Queue is not a class, it's an interface. The concrete class you're using is LinkedList.More...
View ArticleAnswer by Federico klez Culloca for Install JDK on Linux with .tar.gz archive
Given what you wrote in your comments, you downloaded the 32-bit version of the jdk. You need to download the 64-bit (x86_64) one.You mentioned you are accustomed to Windows running both 32-bit and...
View ArticleAnswer by Federico klez Culloca for String is palindrome or not
A StringBuffer is not a String, thus it will never be equal to a String. Compare st with st1.toString() instead.As an aside, in if(st1.equals(st)==true) comparing a boolean with true is not necessary...
View ArticleAnswer by Federico klez Culloca for How to check What architecture JDK was...
If you only need to check by hand you can use the file utility which, for executables, should tell you what architecture the binary was built for.So assuming you want to know about the javac that's on...
View Article