Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-02-2007, 05:26 AM
Member
 
Join Date: Aug 2007
Posts: 1
Khorod is on a distinguished road
Storing Data
Goodday everyone,

About 3 weeks ago i have started picking up java, and trying to grasp the basics i decided to try and put together a simple yet challenging program.

the program basicly needs to store multiple names and a value that goes with each name to a file, after which i want to be able to edit and change the value.

Now my question is what would be the best way to realise this (keep in mind i might want to display the entire list in a GUI) i was thinking of having an array go through the file each time you want to change a value by searching for the name that the user inputs, however this seems rather difficult in terms of flexibility, i also noticed the Linkedlist in the API, at first glance however it seems this only stores 1 variable (be it string or int) and not 2?

Could someone give me a push in the right direction?

Thanks in advance, Khorod.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-03-2007, 06:48 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,124
hardwired is on a distinguished road
A fascinating question because there are so many possibilities.
Some suggestions:
A List (LinkedList, ArrayList, etc) can take any kind of object including another List, an array (or multi-dimensional array) or a custom class object.
A "Data Store" class can have any thing you want in it along with methods such as write or draw.
For instance:
Code:
class PseudoStore { String name; int id; public PseudoStore(String name, int id) { this.name = name; this.id = id; } public String toString() { return "PseudoStore[name:" + name + ", id:" + id + "]"; } }
Then you could do
Code:
// For generics (j2se 1.5+) List<PseudoStore> list = new ArrayList<PseudoStore>(); // or, for non-generics List list = new ArrayList(); list.add(new PseudoStore("John Hancock", 22)); ... String name = ((PseudoStore)list.get(0)).name; ... for(int j = 0; j < list.size(); j++) { PseudoStore store = (PseudoStore)list.get(j); System.out.println("store("+j+") = " + store); }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Why import isnt needed whn ref is used without storing to local variable N_i_X Advanced Java 2 03-31-2008 06:11 AM
storing and retrieving a file as such anil_manu Advanced Java 0 03-11-2008 02:27 PM
Storing data permanently shaungoater New To Java 2 03-10-2008 05:18 PM
Reading form inputStream and storing in ByteArray Java Tip Java Tips 0 11-27-2007 11:23 AM
Problem with storing and retrieving from a textfile Albert Advanced Java 1 07-13-2007 04:01 PM


All times are GMT +3. The time now is 09:04 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org