How to print an arrayList in Java, printing "last in - first out" -


Then this is my problem / question:

The assignment is to write a program that takes in N string The quantities, which are words or sentences, then print the strings by "the last, first out" - in this sentence, counting words and counting it is my code so far, but how can I print the previous X inputs Am I

Import static javax.swing.JOptionPane. *; Import java.util.ArrayList; Public class Moment2 {Public static zero main (string [] Args) {String Indet; integer number; Indicate = ShowInputDialog ("Who Megaga Stranger Ska Rockes?"); Count = integer Paracet (Indet); String handwriting last word = null; While (true) {ArrayList & lt; String & gt; Manning = new arrelisted & lt; String & gt; (); String ord = showInputDialog ("Skip to item or Manning Ennar, cancel" 'Cancel'.); If (ord == null) {break; } And {// calculation ++; Mening.add (ord); Last word = new string handler (ord); }} Print (last word, count); } Public static void Print (StringHandlerY lastWord, integer stringCount) {showMessageDialog (Zero, "Do tryckte 'Cancel' \ NDU every givit" + stringCount + "strängar." + "\ NSträngen: \ n" + LastWord.getString () + "', Every" + Last Word.getWords () + "ord"); }}

// This is in a separate file:

  public class StringHandlerY {static int nrOfObjects; Private string str; // Constructor StringHandler Y (string s) {str = s; } // Accessor / Gestures - Returning NAN Jining Int Whitswold () {string [] template = it. Stratospatus (""); Int i = temp.length; Return i; } String getString () {return this.str; }} ** strong text **  text  

latestStringTry pile which already exists and delete Allows the final element of:

  stack & lt; String & gt; StringStack = new stack & lt; String & gt; (); StringStack.push ("Hello World"); StringStack.push ("Hi World"); String latest string = stringStack.pop (); Println. ("Size with" + latestString.split ("\\ s +") Length was "previous string" + latestString +);  

If you want to try LinkedList sticking with the list then as below:

  LinkedList & LT; String & gt; String List = New Linkedist & lt; String & gt; (); StringList.add ("Hello World"); StringList.add ("Hi world"); String latest string = string list .removeLast (); Println. ("Size with" + latestString.split ("\\ s +") Length was "previous string" + latestString +);  

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -