Dear all.
Thanks for you kind and generous supporting.
From the String s="<hell <world </world </hell";
I wanted push the elements "<hello, <world" into stack, and pop off if current element equal to peek element in stack.
Question: Even stack.peek().equals(CURRENT ELEMENT), why can not pop off, but occurs error??
Please give me your suggestion. PLEASE!!!!
import java.util.*;
public class GomiTest{
public static void main(String[] args){
Stack<String> stack = new Stack<String>();
String s="<hell <world </world </hell";
String temp[]=null;
String jin;
temp=s.split(" ");
for(int i=0;i<temp.length;i++){
if(temp[i].startsWith("</")){
jin=temp[i].replace("/","");
//System.out.println("jin "+jin);
if(!stack.empty()&&stack.peek().equals(jin)){
System.out.println("pop "+stack.pop());
}else{
System.out.println("error");
}
// System.out.println("pushed "+temp[i].replace("</",""));
}else if(temp[i].startsWith("<")){
//jin=temp[i].replace("<","");
System.out.println("pushed "+temp[i]);
}else{
System.out.println("other "+temp[i]);
}
}
}
}