Code example for Scanner

Methods: nextLong, useLocale, useRadix

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.nextLong();
            fail("Should throw InputMismatchException");
        } catch (InputMismatchException e) {
            // Expected 
        } 
        s.useLocale(Locale.ENGLISH);
        // If exception is thrown out, input will not be advanced. 
        assertEquals(23456, s.nextLong());
        assertEquals(23456, s.nextLong());
 
        /* 
         * ''' is used in many locales as group separator. 
         */ 
        s = new Scanner("23'456 23'456");