Method to split a java string object into multiple fragments


The Java String class defines the following method to split a Java String object into multiple fragments of substrings and store them in a returned String array:

String[] split( String regularExpression)

The regularExpression argument specifies a delimiter or separator pattern. More detailed information can be found in the Java Document API (https://java.sun.com/javase/6/docs/api/). The following example uses "-" as a separator to split a String object:

String initialString = "1:one-2:two-3:three";
String[] fragments = initialString.split("-");

The resulting fragments array contains three Strings of "1:one", "2:two", and "3:three". One can further split these fragments if needed. For example, 

String[] pair1 = fragments[0].split(":");

The pair1 array contains two String objects of "1" and "one". 

Given the following line in a text file:

A=Excellent B=Good C=Adequate D=Marginal E=Unacceptable

Write a method that 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

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: Method to split a java string object into multiple fragments
Reference No:- TGS0106617

Expected delivery within 24 Hours