Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I found a few weird constructs in Java that the compiler allows, but for which I'm not sure what could be the practical use.
1) if statement:
if((score=score+10) > 110); //No if body
while eg: switch(++i); is not
2) for loop:
for(;;); //No loop body
Are there practical, valid circumstances to use the preceding code?
This:
if((score=score+10) > 110);
is equivalent to:
score += 10;
but has no practical use otherwise.
This:
for(;;);
loops forever doing nothing - not particularly useful, unless you wanted to create a permanently busy thread perhaps for testing purposes.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Regular expression only accepts 0 or 5.
Is there a regex expression to evaluate that?
Thanks.
You can use either "0|5" or "[05]". The first is an alternative, the second is a character class. They will behave identically. See the documentation for Pattern for more information on the building blocks for regular expressions.
Read this. And use this:
"^[05]$"
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Why doesn't java.lang.Short (or Float or Double) class have a reverse method similar to java.lang.Integer ?
They both do have reverseBytes method though.
Why isn't the API list consistent ?
short can hold 2 bytes and it would have made sense to have a reverse method as well.
Wouldn't it ?
Thanks
While I agree on the API criticism, it's pretty simple to emulate:
short input = ...;
short reversed = (short)(Integer.reverse(input) >> 16);
So maybe the answer is:
Not enough people felt it was necessary
It's easy enough to simulate
Someone wanted to show off with the implementation of Integer.reverse()
Every line of code needs to maintained. Less code == less bugs, lower cost, easier maintenance.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I need to define specific numbers out of an array of 52 numbers so I can assign them an image (yes I am creating an applet). I don't think that code is necessary for any of you to answer this question. Any help would be fantastic.
I'm not sure I understand what you're asking. You can set an item in an array this way:
myArray[4] = 52;
That would set array index #4 (remember it's zero based so it's actually the 5th item) to the value of 52. Is that what you're looking for?
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am developing a Java program and I'm meeting cases where I get undecided whether to use the casting a string to integer method, or to use the integer.parseInt method. Is there any clear benefit for either of the two methods?
With 'casting to string method', I mean:
String.valueOf(integer);
As far as I know, it's not possible to cast from a String to an int, so using Integer.parseInt seems like the best option here.
Looking at your edits about using valueOf, perhaps this link may help: Integer.valueOf() vs. Integer.parseInt()
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have tried to return null as third value in my boolean function, but it won't compile. I need to return three values from my class method - true, false and null (for example). Is there any standard way how can I do it?
Please use an enumeration with three values defined. Hacking things together is no solution.
Similar question has been asked, it should help.
You can make your own POJO object with this logic in getXX() method. From your method return this POJO with value and test it in code.
Generaly, don't use null values as state indicators.