-1
Вот что я до сих пор:Java: Stack -> ArrayList
System.out.println("\fStack - ArrayList Demo\n");
ArrayList<String> al = new ArrayList<String>();
Stack<String> st = new Stack<String>();
// Start with a few elements to the ArrayList
al.add("A");
al.add("B");
al.add("C");
st.addAll(al); // Retrieve ArrayList elements for the stack and add them there
al.clear(); // Clear arraylist for storage later
// Pop out the last element in the stack.
System.out.println("\nPop out the last element: "+al.add(st.pop()));
System.out.println("What's left of the stack: "+st+"\n");
System.out.println("ArrayList, now: "+al);
// Keep popping..
int count = st.search("A");
while (count != -1 && count >= 1) {
System.out.println("Popping next.."+al.add(st.pop()));
count--;
}
// Is the Stack empty?
System.out.println("\nStack Empty? "+st.empty());
System.out.println("ArrayList now: "+al);
Использование al.add(st.pop()));
возвращает "истина", когда я запускаю программу. Есть ли способ заставить его дать фактический элемент, который выскочил (A, B, C)?
String element = st.pop(); System.out.println ("element is" + element); al.add (элемент); –
String elm = st.pop(); al.add (ильм); ? – kufudo
@RonDahlgren: и kufudo: вы можете разметки 'code' в комментариях, окружая его обратными шагами:' – jlordo