<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>effectiveness &#8211; CodePills.com</title>
	<atom:link href="https://codepills.com/tag/effectiveness/feed/" rel="self" type="application/rss+xml" />
	<link>https://codepills.com</link>
	<description>Helping you make a better code</description>
	<lastBuildDate>Sun, 19 Jun 2022 17:23:54 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>How to convert int to long in Java?</title>
		<link>https://codepills.com/how-to-convert-int-to-long-in-java/</link>
					<comments>https://codepills.com/how-to-convert-int-to-long-in-java/#respond</comments>
		
		<dc:creator><![CDATA[Andrej Buday]]></dc:creator>
		<pubDate>Tue, 11 Feb 2020 14:38:44 +0000</pubDate>
				<category><![CDATA[Tips & tricks]]></category>
		<category><![CDATA[conversion]]></category>
		<category><![CDATA[effectiveness]]></category>
		<category><![CDATA[primitive data types]]></category>
		<guid isPermaLink="false">https://codepills.com/?p=1054</guid>

					<description><![CDATA[This article is a simple hint on the question of converting int to long or Long in Java. <a href="https://codepills.com/how-to-convert-int-to-long-in-java/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p>This article is a simple hint on the often asked question of converting int to long or Long in Java.</p>
<p><span id="more-1054"></span></p>
<h2>How to convert int to long in Java?</h2>
<p>When we want to convert primitive <code>int</code> datatype to primitive <code>long</code> data type, all we need to do is just assign primitive <code>int</code> to primitive <code>long</code> variable. Nothing else is necessary. Converting primitive data type from higher to lower data type is implicit.</p>
<p>Let&#8217;s look on the example how to convert int to long in Java:</p>
<pre><code class="language-java">public class Main {
    public static void main(String args[]) {
        int primitiveInt = 1000;
        long primitiveLong = primitiveInt;
        System.out.println(primitiveLong);
    }
}</code></pre>
<p><b>Output</b></p>
<pre><code class="language-bash">1000</code></pre>
<h2>How to convert int to Long in Java?</h2>
<p>When we want to convert primitive <code>int</code> datatype to a Long object, there are two different ways to do it.</p>
<p>We can:</p>
<ul>
<li>instantiate new Long class over int constructor.</li>
<li>use a static method to extract primitive int and create a new Long object (calling Long.valueOf() method).</li>
</ul>
<p>Let&#8217;s look on the example how to convert int to long in Java:</p>
<pre><code class="language-java">public class Main {
    public static void main(String args[]) {
        int primitiveInt = 1000;

        // Option #1 - constructor initiation
        final Long objectLong = new Long(primitiveInt);
        // Option #2 - use static method
        final Long objectLongOther = Long.valueOf(primitiveInt);

        System.out.println(objectLong);
        System.out.println(objectLongOther);
    }
}</code></pre>
<p><b>Output</b></p>
<pre><code class="language-bash">1000
1000</code></pre>
]]></content:encoded>
					
					<wfw:commentRss>https://codepills.com/how-to-convert-int-to-long-in-java/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
