Java: Scanner umie ciąć tekst, nawet na inty itp
Niesamowite funkcje Scannera! Oprócz wczytywania tekstu wpisanego przez użytkownika i czytania plików, potrafi on znacznie więcej.
Oto cytat ze strony:
Oto cytat ze strony:
Parameter
Data Type | Parameter | Description | Required/Optional |
---|---|---|---|
String | pattern | It is a string specifying the pattern to scan. | Required |
Pattern | pattern | It is the pattern to scan for specified string. | Required |
Returns
Method | Returns |
---|---|
hasNext() | This method returns true if and only if this scanner has another token. |
hasNext(String pattern) | This method returns true if and only if this scanner has another token matching the specified pattern. |
hasNext(Pattern pattern) | This method returns true if and only if this scanner has another token matching the specified pattern. |
Exceptions
IllegalStateException- This method throws exception if the innvocation is done after the scanner has been closed.
Compatibility Version
Java 1.5 and above
Example 1
Output:
Delimiter:\p{javaWhitespace}+ Hello World!
Example 2
Output:
Result: true String: Hello, This is JavaTpoint. Final Result: false
Example 3
Output:
Pattern found
Example 4
Output:
Result: true Result: false Rest of String: JavaTpoint.com 15 + 15 = 18.0
Example 5
Output:
Pawan Suresh
Komentarze
Prześlij komentarz