Questions tagged [value-of]
138 questions
520
votes
11 answers
Difference between parseInt() and valueOf() in Java?
How is parseInt() different from valueOf() ?
They appear to do exactly the same thing to me (also goes for parseFloat(), parseDouble(), parseLong() etc, how are they different from Long.valueOf(string) ?
Also, which one of these is preferable and…

Ali
- 261,656
- 265
- 575
- 769
150
votes
7 answers
Override valueof() and toString() in Java enum
The values in my enum are words that need to have spaces in them, but enums can't have spaces in their values so it's all bunched up. I want to override toString() to add these spaces where I tell it to.
I also want the enum to provide the correct…

WildBamaBoy
- 2,663
- 6
- 25
- 23
34
votes
6 answers
Differences between new Integer(123), Integer.valueOf(123) and just 123
Recenlty I saw code (Java) like this:
myMethod(new Integer(123));
I am currently refactoring some code, and there is a tip in Sonar tool, that it's more memory friendly to use sth like this:
myMethod(Integer.valueOf(123));
However in this case, I…

MicNeo
- 716
- 3
- 12
- 20
26
votes
2 answers
Where does the Enum.valueOf(String) method come from?
In Java SE 7 (and most probably in previous versions) the Enum class is declared like this:
public abstract class Enum>
extends Object
implements Comparable, Serializable
The Enum class has a static method with this…

Razvan
- 9,925
- 6
- 38
- 51
24
votes
2 answers
How can i insert timestamp with timezone in postgresql with prepared statement?
I am trying to insert to a timestamp with timezone field of my DB a string which includes date, time and timezone using prepared statement.
The problem is that Timestamp.valueof function does not take into consideration the time zone that the string…

Mike Vasi
- 467
- 2
- 5
- 16
11
votes
1 answer
XSL for-each and value-of
Given the xml:
text
...
text
And xsl:
...
What do I need to put inside the for-each loop to access the text? There doesn't seem to be a corresponding…

Sandy Vanderbleek
- 1,082
- 1
- 12
- 13
11
votes
3 answers
Java - enum valueOf "override" naming convention
Say you have the following enum:
public enum Color {
RED("R"), GREEN("G"), BLUE("B");
private String shortName;
private Color(String shortName) {
this.shortName = shortName;
}
public static Color getColorByName(String…

Alin Stoian
- 1,122
- 1
- 12
- 24
9
votes
3 answers
Java: valueOf vs copyValueOf
What is the difference between valueOf and copyValueOf. I looked on GrepCode, only to find that both return the exact same thing.
copyValueOf:
Parameters:
data the character array.
Returns:
a String that contains the characters of the character…

StarCoder
- 251
- 1
- 3
- 16
9
votes
4 answers
What does line.split(",")[1] mean [Java]?
I came across code where i had encountered with Double.valueOf(line.split(",")[1])
I am familiar with Double.valueOf() and my problem is to understand what does [1] mean in the sentence. Searched docs didn't find anything.
while ((line =…

SmashCode
- 741
- 1
- 8
- 14
9
votes
4 answers
How to assign a very large number to BigInteger?
Given the following input:
4534534534564657652349234230947234723947234234823048230957349573209483057
12324000123123
I have attempted to assign these values to BigInteger in the following way.
public static void main(String[] args) {
…

crmepham
- 4,676
- 19
- 80
- 155
8
votes
2 answers
Equality comparison between Date and number doesn't work
According to the ECMA script standard, the following code should return true, but it doesn't:
d = new Date() ;
d.setTime(1436497200000) ;
alert( d == 1436497200000 ) ;
Section 11.9.3 says:
If Type(x) is either String or Number and Type(y) is…

GetFree
- 40,278
- 18
- 77
- 104
8
votes
4 answers
Set fields with reflection - String has no valueOf(String) method
I'm setting public fields of the Object this via reflection. Both the field name and the value are given as String. I use several various field types: Boolean, Integer, Float, Double, an own enum, and a String.
It works with all of them except with…

fabb
- 11,660
- 13
- 67
- 111
7
votes
3 answers
xsl:value-of used as xsl:element name
I have an incoming XML file with a list structure:

Thomson Comer
- 3,919
- 3
- 30
- 32
7
votes
1 answer
Outputting value of xsl:variable with xsl:value-of problem
I think I may have a misunderstanding of and so perhaps someone can correct me!
I'm attempting to tweak some hardcoded banners to be a bit cleaner so I thought it would be a good idea to create an …

xan
- 7,440
- 8
- 43
- 65
6
votes
5 answers
Retrieve all the attribute values from XML using XSLT
I can't figure out how to access all the attributes in a tag from an XML document.
Let's say I have the following XML:

Erik Åstrand
- 369
- 2
- 5
- 14