Home Java javaTutorial The difference between valueOf, parseInt and toString in Java

The difference between valueOf, parseInt and toString in Java

May 25, 2017 pm 02:50 PM

1.parseInt() converts the String type into the int type.
Such as String a= "123";

int
 b = 
Integer
.parseInt(a);

This way b is equal to 123.

2.ValueOf() method, for example, Integer.valueOf() converts the String type into the Integer type (note: it is the Integer type, not the int type. The int type is a simple type that represents numbers, and the Integer type It is a complex type that refers to )
For example:

String a= "123";
Integer c =Integer.valueOf(a);
//Integer类型可以用int
Value方法
转化为int类型
int b =c.intValue();

At this time, b is equal to 123

String.valueOf(int) returns the string representation of the int parameter.

This representation happens to be the result returned by the single-parameter Integer.toString method.

3. toString() can convert a reference type into the String string type.
The following example is the opposite of 2, converting Integer into String type:

Integer a = 
new
 Integer(123);
String b =a.toString();

At this time, b is "123"

[Related recommendations]

1. Detailed explanation of valueOf method examples in java

2. The difference between valueOf and toString, (String) in Java

3 . Usage of tostring() and valueof() and the difference between the two

4.In-depth understanding of valueOf function and toString method

5. Introduction to object conversion functions toString() and valueOf()_

6. Use toString() method to return time as a string

The above is the detailed content of The difference between valueOf, parseInt and toString in Java. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Ethereum, a blockchain platform that surpasses Bitcoin, with advantages and innovation inventory Ethereum, a blockchain platform that surpasses Bitcoin, with advantages and innovation inventory Aug 06, 2025 pm 11:57 PM

Through its Turing-complete smart contracts, EVM virtual machines and Gas mechanisms, Ethereum has built a programmable blockchain platform beyond Bitcoin, supporting diversified application ecosystems such as DeFi and NFT; its core advantages include a rich DApp ecosystem, strong programmability, active developer community and cross-chain interoperability; it is currently implementing consensus transformation from PoW to PoS through the upgrade of Ethereum 2.0, introducing beacon chains, verifier mechanisms and punishment systems to improve energy efficiency, security and decentralization; in the future, it will rely on sharding technology to realize data sharding and parallel processing, greatly improving throughput; at the same time, Rollup technology has been widely used as a Layer 2 solution, Optimistic Rollup and ZK-Rollu

How to obtain digital currency BTC? What are the differences between btc and digital currency? How to obtain digital currency BTC? What are the differences between btc and digital currency? Aug 01, 2025 pm 11:15 PM

There are four main ways to obtain BTC: 1. Register and exchange it with fiat currency or other digital assets through centralized trading platforms such as Binance, OK, Huobi, and Gate.io; 2. Participate in P2P platforms to directly trade with individuals, and pay attention to the credit risks of the counterparty; 3. Provide goods or services to accept BTC as payment; 4. Participate in airdrops, competitions and other platform reward activities to obtain a small amount of BTC. The core difference between BTC and digital currency is: 1. BTC is a type of digital currency, which belongs to a genus relationship; 2. BTC adopts a proof of work (PoW) mechanism, while other digital currencies may use various technologies such as proof of stake (PoS); 3. BTC emphasizes the value storage function of "digital gold", and other digital currencies may focus on payment efficiency or

From blockchain to cryptocurrency, a complete analysis of basic concepts From blockchain to cryptocurrency, a complete analysis of basic concepts Aug 06, 2025 pm 11:51 PM

Blockchain is a distributed and decentralized digital ledger technology. Its core principles include: 1. Distributed ledger ensures that data is stored simultaneously on all nodes; 2. Encryption technology, linking blocks through hash values to ensure that data is not tampered with; 3. Consensus mechanisms, such as PoW or PoS, ensure that transactions are agreed between nodes; 4. Decentralization, eliminating single point of control, enhancing censorship resistance; 5. Smart contracts, protocols for automated execution. Cryptocurrencies are digital assets issued based on blockchain. The operation process is: 1. The user initiates transactions and signs digitally; 2. The transactions are broadcast to the network; 3. The miner or verifier verifies the validity of the transaction; 4. Multiple transactions are packaged into new blocks; 5. Confirm the new zone through consensus mechanism

Blockstream launches Simplicity to bring new alternatives to Ethereum (ETH) Solidity Blockstream launches Simplicity to bring new alternatives to Ethereum (ETH) Solidity Aug 06, 2025 pm 08:45 PM

The rise of a dedicated smart contract programming language for different architectures. Blockstream, led by AdamBack, officially launched Simplicity, a native smart contract language designed for Bitcoin, providing Ethereum's Solidity with a new competitive option. As the creator of Liquid, Bitcoin’s second-layer network, Blockstream has a deep background in the field of encryption, and its leader AdamBack is a key figure in the history of Bitcoin’s development. The Simplicity language released this time aims to introduce stronger programmability into the Bitcoin ecosystem. According to the company's news to Cointelegraph on Thursday, Simplicit

The computer's system tray icon is messy, how to organize it? The computer's system tray icon is messy, how to organize it? Aug 21, 2025 pm 08:12 PM

Hide the system tray icon without affecting the program operation, only removes the visual display; 2. Completely clean up and disable non-essential startup items through the task manager; 3. Resolve the mess and uninstall the software and develop the habit of canceling the bundling and checking during installation, so as to achieve the dual goals of visual refreshing and resource optimization.

What is Ecocoin (EOS)? EOS Market Analysis and Price Forecast 2025-2030 What is Ecocoin (EOS)? EOS Market Analysis and Price Forecast 2025-2030 Aug 14, 2025 pm 12:03 PM

Table of Contents What is EOS? Project Background Project Category 1. Smart Contract Layer-1 Infrastructure 2. Delegated Proof of Stake (DPoS) Ecosystem 3. Web3dApp and Developer Ecosystem Strategies Outlook Market Analysis Price Analysis Price Forecast: EOS2025-203025 Forecast 2026 Forecast 2027 Forecast 2028-2030 Forecast Price Forecast Table Project Overview FAQ Conclusion Since its ambitious launch, EOS.IO is recognized as one of the most technologically advanced blockchain platforms, aiming to solve the scalability faced by traditional networks like Ethereum

What is the difference between tokens, tokens, and tokens? What is the difference between tokens, tokens, and tokens? Aug 16, 2025 pm 12:36 PM

Token is a general term for digital assets on the blockchain. Tokens emphasize their currency and transaction attributes, while tokens highlight their voucher functions that represent rights and interests.

Smart Contracts - Automatic Execution Protocol on Blockchain Smart Contracts - Automatic Execution Protocol on Blockchain Aug 06, 2025 pm 11:48 PM

Smart contracts are automatic execution programs stored on blockchains. The core is to implement the "if... then..." logic through code to execute protocols in a decentralized and tamper-free way. 1. Write code: define contract logic using languages such as Solidity; 2. Compile: convert the code into machine-readable bytecode; 3. Deploy: publish the bytecode to the blockchain through transactions and generate a unique address; 4. Trigger execution: When the preset conditions are met, the contract will run automatically; 5. Record the result: All operations are permanently recorded on the chain to ensure transparency and verifiability. It solves the trust, efficiency, cost, transparency and execution risks in traditional protocols, and is widely used in DeFi, supply chain, copyright management, voting, insurance and gaming fields.

See all articles