Answer 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 ArticleAnswer by Federico klez Culloca for when using java return vs break
In this case it works because break exits the loop and goes to the end of the method which immediately returns. Which is functionally equivalent to returning immediately.But in this case, for...
View ArticleAnswer by Federico klez Culloca for Does the original list decrease in size...
They may point to the same elements but they're different containers. The Queue is not backed by that list. References to the elements are copied from the list to the queue, but if you remove something...
View ArticleJavascript phone number validation
I need to validate a phone number in javascript.The requirements are:they should be 10 digits, no comma, no dashes, just the numbers, and not the 1+ in frontthis is what I wrote so farfunction...
View ArticleAnswer by Federico klez Culloca for Why Is It Called Memoization?
Exactly because it's NOT "memorization" and has a specific meaning beyond simply memorizing something. I.e., you're memorizing something for a specific purpose (a performance benefit, not simply...
View ArticleComment by Federico klez Culloca on Different base64 encoding validation in...
@gstackoverflow I'd say go with John Skeet's answer instead.
View ArticleAnswer by Federico klez Culloca for Does method Optional.of do a type...
Because in your second example Optional.of() expects an X and new Y()is an X.But, as you state, an Optional<Y> is not an Optional<X>, hence the first example doesn't work.More generally a...
View ArticleAnswer by Federico klez Culloca for How to turn a optional of an string array...
Looks to me like a simple map operation with String.join().Optional<String[]> given = Optional.ofNullable(new String[]{"a", "b"});var joinedString = given.map(s -> String.join("",...
View ArticleAnswer by Federico klez Culloca for I want to add numbers from 1 to 16 to...
The problem in your code is that i is used as the loop index, not only as the value you want to put inside the list.Suppose i = 11, at which point you double it, which makes it 22. You told the for to...
View ArticleAnswer by Federico klez Culloca for Java static members of abstract classes
You should encapsulate the capacity in a getCapacity method. That method can then look for an appropriate static variable for the specific class, so for example:abstract class Vehicle { public int...
View ArticleAnswer by Federico klez Culloca for Need to understand map.get() method after...
HashMap's getchecks for equality with == before using equals.So the fact that you're using the same object you used as a key (rather than an object with the same content but a different reference)...
View ArticleComment by Federico klez Culloca on Java casting variable to Double when...
The first case are a double and an int, not a Double and an Integer, so it returns a double which then gets autoboxed to a Double
View ArticleAnswer by Federico klez Culloca for Java Stream API - Lazy Evaluation
That's explicitly spelled out in the documentation for count (emphasis mine)An implementation may choose to not execute the stream pipeline (either sequentially or in parallel) if it is capable of...
View ArticleComment by Federico klez Culloca on IntelliJ IDEA asks me to update gradle
I'm not sure I understand why you're downgrading fabric loom instead of upgrading gradle, which seems to be the better choice
View ArticleComment by Federico klez Culloca on Multiple Inheritance in C# Two Parent...
This question is similar to: Multiple Inheritance in C# (see the second answer in particular). If you believe it’s different, please [edit] the question, make it clear how it’s different and/or how the...
View ArticleComment by Federico klez Culloca on Why is my output different after each...
"For some reason" I suppose it has something to do with the main method being defined without parameters.
View ArticleAnswer by Federico klez Culloca for Why is GLOB called GLOB? What is the full...
The glob command, short for global, originates in the earliest versions of Bell Labs' Unix.From Wikipedia
View ArticleComment by Federico klez Culloca on Why i Have Null Pointer Exception on...
"then" meaning what, exactly? Please post a minimal reproducible example and the resulting stack trace, pointing out on what line the exception happens.
View ArticleComment by Federico klez Culloca on Mention team in DevOps
Please don't tag unrelated languages (java, in this case). I already removed it for you.
View ArticleComment by Federico klez Culloca on How can I show images in Angular from MySQL?
Hello and welcome. "i get an error", "getting a lot of errors in the console log every second": you should please [edit] your question to include those errors, otherwise we can just throw guesses here.
View ArticleComment by Federico klez Culloca on Connecting to Vertica DB via SSH Tunnel...
Have you tried connecting to that host via a known-working client?
View ArticleComment by Federico klez Culloca on VS Code Red Hat Java Extension...
By the way, those are only visual clues, they're not actually inserted in the source code (they would cause a syntax error if they were).
View ArticleComment by Federico klez Culloca on save rtsp to mp4
You may want to [edit] your question to include how this doesn't work. Are you getting exceptions? The app crashes? Nothing happens? In other words, what steps have you taken in debugging this?
View ArticleComment by Federico klez Culloca on How to download file from a given link...
My impression from your description is that this is the sort of situation where you would click a download button, the server generates a download link/button that you click and the download starts....
View ArticleAnswer by Federico klez Culloca for Enums in Java: empty line with semicolon?
As per the spec, an enum is defined as { [EnumConstantList] [,] [EnumBodyDeclarations] } Further EnumBodyDeclarations is defined as; {ClassBodyDeclaration} Notice the leading ;Since the...
View ArticleComment by Federico klez Culloca on Why does Java Date always display in...
Nope, that's the third-party library's problem. I'm afraid, without knowing how that library works, your only choice is to move the time forward 3 hours to compensate.
View ArticleComment by Federico klez Culloca on How to detect a cycle in a Singly Linked...
Please [edit] your question to specifically and clearly define the problem that you are trying to solve. In particular what happens after you solved the issue you yourself identified. (besides, why...
View Article