Here you can find the source of toLong(String string)
Parameter | Description |
---|---|
string | A String containing an integer. |
public static long toLong(String string)
//package com.java2s; // are made available under the terms of the Eclipse Public License v1.0 public class Main { /**/* w w w . ja v a 2 s . c om*/ * Convert String to an long. Parses up to the first non-numeric character. If no number is found an IllegalArgumentException is thrown * * @param string * A String containing an integer. * @return an int */ public static long toLong(String string) { long val = 0; boolean started = false; boolean minus = false; for (int i = 0; i < string.length(); i++) { char b = string.charAt(i); if (b <= ' ') { if (started) break; } else if (b >= '0' && b <= '9') { val = val * 10L + (b - '0'); started = true; } else if (b == '-' && !started) { minus = true; } else break; } if (started) return minus ? (-val) : val; throw new NumberFormatException(string); } }