I need some help in Undo function in Java

I write a Text Editor with Java , and I want to add Undo function to it

but without UndoManager Class , I need to use a Data Structure like Stack or LinkedList but the Stack class in Java use Object parameters e.g : push(Object o) , Not Push(String s) I need some hints or links . Thanks


Assuming you are using Java 5, Stack is a generic class. You can instantiate it according to the objects it should hold.

You can then use:

Stack<String> stack = new Stack<String>();
String string = "someString";

Also note that in the case you are using Java 1.4 or below, you can still push String objects into the stack. Only that you will need to explicitly downcast them when you pop() them out, like so:

Stack stack = new Stack();
String string = "someString";

String popString = (String) stack.pop(); // pop() returns an Object which needs to be downcasted

Need Your Help

How to provide web access to interact with a file system?

webserver file-sharing sshfs

I need to be able to provide web access to interact with a file system, to upload and download files to a directory. In general people will access these files using sshfs but in a pinch we want peo...

How to handle not filled EditText in Android

android variables input error-handling null

I want to code a simple calculator with 3 inputs (NUM1,NUM2,NUM3), 3 buttons(SUM,SUB,MUL) and 1 RESULT text plane. In my app if I give all inputs, the app works correctly. However if I don't give any

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.