Reference no: EM1315524
The Java String class explains the following method in order to split a Java String object into several fragments of the substrings and store them in a returned String array:
String[] split( String regularExpression)
The regularExpression argument signigy a delimiter or separator pattern.
String initialString = “1:one-2:two-3:three”;
String[] fragments = initialString.split(“-“);
The resulting fragments array consists of three Strings of “1:one”, “2:two”, and “3:three”. One may split these fragments further if required. For example,
String[] pair1 = fragments[0].split(“:”);
The pair1 array consists of two String objects of “1” and “one”.
Provide the following line within a text file:
A=Excellent B=Good C=Adequate D=Marginal E=Unacceptable
Write down a method which would read this text file and print out the followings:
Grade A is Excellent.
Grade B is Good.
Grade C is Adequate.
Grade D is Marginal.
Grade E is Unacceptable.