Java string with operator is converted to long type

Source: Internet
Author: User

Because the project needs to configure a refresh time in the configuration file, the data taken out of the configuration file is definitely a string, and then the string with the operator is converted to a long type. The specific code is as follows:

In configuration file system.properties:

1 reflash_time = (2*60*1000)

The Java code takes out the value:

1  Public Static Final String reflashtime = "Reflash_time"; 2  3  Public String reflashtime; 4  5 reflashtime = Prop.getproperty (reflashtime). Trim ();

The string is split by *, the number is saved in an array, and then multiplied to get its value:

1 string[] Reflash = Reflashtime.split ("\\*"2  3 for (int i = 0; i < reflash.length; i++) {4     reflashtime *= long.parselong (Reflash[i]); 5 }6  7 System.out.println (reflashtime);

This enables the conversion of a string with an operator to an integral type.

Java string with operator is converted to long type

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.