Java Stack to stack2String(Stack stack)

Here you can find the source of stack2String(Stack stack)

Description

stack String

License

Open Source License

Declaration

public static String stack2String(Stack stack) 

Method Source Code


//package com.java2s;
/*//from  w w w  . j  av a  2  s .  c om
Copyright (C) 2011 Vasili Gavrilov
    
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
    
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
    
You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

import java.util.Stack;

public class Main {
    public static String stack2String(Stack stack) {
        Object[] strings = (Object[]) stack.toArray();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < strings.length; i++)
            sb.append(strings[i]);

        return sb.toString();
    }
}

Related

  1. stackToList(Stack stack)
  2. stackToTuple(Stack s)