A string containing text and possibly delimiters has been split into tokens and stored in String[] tokens. Each token is either an open delimiter, a close delimiter, or a substring that is not a delimiter. You will write the method getDelimitersList, which returns an ArrayList containing all the open and close delimiters found in tokens in their original order.  Eg) (,), ,   import java.util.*;  public class Delimiters  {  /** The open and close delimiters **/  private String openDel;  private String closeDel;  /** Constructs a Delimiters object were open is the open delimiter and close is the  * close delimiter.  * Precondition: open and close are non-empty strings  */  public Delimiters (String open, String close)  {  openDel = open;  closeDel = close;  }  /** Returns an ArrayList of delimiters from the array tokens, as described in part (a). */  public ArrayList getDelimitersList(String[] tokens)  {  /* to be implemented in part a */  }  public static void main(String[] args)  {  Delimiters d1 = new Delimiters("(", ")");  String[] tokens = {"(", "x + y", ")", " * 5" };  ArrayList res1 = d1.getDelimitersList(tokens);  System.out.println("It should print [(, )] and it prints" + res1);  Delimiters d2 = new Delimiters("", "");  String[] tokens2 = {"", "yy", "", "zz", ""};  ArrayList res2 = d2.getDelimitersList(tokens2);  System.out.println("It should print [, , ] and it prints " + res2);  }  }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

A string containing text and possibly delimiters has been split into tokens and stored in String[] tokens. Each token is either an open delimiter, a close delimiter, or a substring that is not a delimiter. You will write the method getDelimitersList, which returns an ArrayList containing all the open and close delimiters found in tokens in their original order. 

Eg) (,),<q> , </q> 

import java.util.*; 

public class Delimiters 

/** The open and close delimiters **/ 

private String openDel; 

private String closeDel; 

/** Constructs a Delimiters object were open is the open delimiter and close is the 

* close delimiter. 

* Precondition: open and close are non-empty strings 

*/ 

public Delimiters (String open, String close) 

openDel = open; 

closeDel = close; 

/** Returns an ArrayList of delimiters from the array tokens, as described in part (a). */ 

public ArrayList<String> getDelimitersList(String[] tokens) 

/* to be implemented in part a */ 

public static void main(String[] args) 

Delimiters d1 = new Delimiters("(", ")"); 

String[] tokens = {"(", "x + y", ")", " * 5" }; 

ArrayList<String> res1 = d1.getDelimitersList(tokens); 

System.out.println("It should print [(, )] and it prints" + res1); 

Delimiters d2 = new Delimiters("<q>", "</q>"); 

String[] tokens2 = {"<q>", "yy", "</q>", "zz", "</q>"}; 

ArrayList<String> res2 = d2.getDelimitersList(tokens2); 

System.out.println("It should print [<q>, </q>, </q>] and it prints " + res2); 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY