Import java.util.regex not working

I get an error when I try to import java.util.regex (by specifically adding a line to find out that the error was in the import, since I only had java.util. * Import previously).

find_glycopeps.java:5: cannot find symbol symbol : class regex location: package java.util import java.util.regex; // Should be redundant... <some more messages about not recognising Pattern and Matcher, which are classes of the regex package> 

As far as I know, the regular expression is the "main" library. I assume that since import java.io. * It works that the native tracking method of where the libraries should work is pretty puzzled about how this happened.

PS: I have to note that I tested some java compilers over the weekend to find 1 that I like and reinstalled the "clean" openjdk-6 this morning, probably these are problems that cause problems, but are not sure how to proceed .

Greetings

EDIT (SOLVED): .. I’m sure to hide from shame now, thanks to everyone for pointing out a truly stupid mistake.

+4
source share
3 answers

Your import is not defined correctly.

You will need to provide an explicit import of each class like this:

 import java.util.regex.Matcher; import java.util.regex.Pattern; 

Or do

 import java.util.regex.*; 

You are trying to import a package, for this you need a metacharacter.

If you read the message that the compiler gives you, it says that it cannot find the regular expression Class .

+12
source

You need to write either:

 import java.util.regex.Matcher; import java.util.regex.Pattern; 

or more:

 import java.util.regex.*; 

You cannot just import java.util.regex without an asterisk, as this is a package; it will be like importing java.io

+4
source

You cannot import a package. You import a class or all classes in a package:

 import java.util.regex.*; 

Packages are organized into a tree, but import not recursive. Import java.util.* Only imports classes in java.util , but not classes from subpackages.

+4
source

Source: https://habr.com/ru/post/1390069/


All Articles