Code example for Scanner

Methods: nextBigInteger, useLocale

0
 
        /* 
         * Different locale can only recognize corresponding locale sensitive 
         * string. ',' is used in many locales as group separator. 
         */ 
        s = new Scanner("23,456 23,456");
        s.useLocale(Locale.GERMANY);
        try { 
            s.nextBigInteger(10);
            fail("Should throw InputMismatchException");
        } catch (InputMismatchException e) {
            // Expected 
        } 
        s.useLocale(Locale.ENGLISH);
        // If exception is thrown out, input will not be advanced. 
        assertEquals(new BigInteger("23456"), s.nextBigInteger(10));
        assertEquals(new BigInteger("23456"), s.nextBigInteger(10));
 
        /* 
         * ''' is used in many locales as group separator. 
         */ 
        s = new Scanner("23'456 23'456");