Java examples for java.lang:String Contain
Checks whether a given string only contains numeric characters and thus is a number.
/******************************************************************************* * Copyright (c) 2008 Dennis Schenk, Peter Siska. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:/*from w w w.ja v a 2s . co m*/ * Dennis Schenk - initial implementation * Peter Siska - initial implementation *******************************************************************************/ //package com.java2s; public class Main { public static void main(String[] argv) { String inputData = "java2s.com"; System.out.println(isNumeric(inputData)); } /** * Checks whether a given string only contains numeric characters and thus is a number. * @param inputData * @return boolean True if a string has numeric characters only, false else. */ public static final boolean isNumeric(final String inputData) { return inputData.matches("-?\\d+(.\\d+)?"); } }