Here you can find the source of removeParenthesis(String text)
Parameter | Description |
---|---|
Text | original string |
public static String removeParenthesis(String text)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.Stack; public class Main { /**// ww w . j a v a 2 s. c o m * Removes parenthesis in a string * @param Text original string * @return altered string */ public static String removeParenthesis(String text) { int pos = text.indexOf('('); if (pos == -1) return text; Stack<Integer> stack = new Stack<Integer>(); pos = 0; while (pos < text.length()) { if (text.charAt(pos) == '(') { stack.push(pos); } else if (text.charAt(pos) == ')') { if (stack.isEmpty()) return text; Integer start = stack.pop(); text = text.substring(0, start) + text.substring(pos + 1); pos = start; continue; } pos++; } return text.replace(" ", " ").trim(); } /** * Checks if an ArrayLis is null or empty * @param AL the list * @return true/false */ public static boolean isEmpty(ArrayList AL) { if (AL == null) { return true; } if (AL.size() == 0) { return true; } return false; } }