Adding & editing strings in vectors

Hi guys,
I need to add a variable (containing a user defined string) to a vector (of type Object!).
Heres a snippet of what I've got so far:
Vector<Student> studentVec = new Vector<Student>(1,1);
     public boolean addStudent(Student p)//Method to add a new student to the end of the student array
          if (currentStudent >= 10) //Checks to make sure vector isn't full
               JOptionPane.showMessageDialog(null, "You have reached the maximum number of students");
               return false;
          else //Adds new student
          {String vecName = students[currentStudent].getName();
               studentVec.add(vecName);               
               return true;
     }Any ideas?
I also have problems when trying to edit the data:
I want to edit the name of the selected Student object, but I seem to have probelms doing it. I've included the setName() function (from the "Student" class (all other functions are contained in "Module" class) below as well if this is any help?
public boolean modifyStudent(Student newData) //Edits the current student
     showCurrentStudent(); //Selects the details about the current student
     studentVec(currentStudent).setName("");
     return false;
public void setName(String n)//Prompts user to set student object's name
     n = JOptionPane.showInputDialog("Enter the name of the student");
     name = n;
}Any help would be greatly appreciated!
Edited by: dugjason on Feb 13, 2008 4:11 PM

* I am sorry for using jdk 1.4
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
// Use gui in Registration class
import java.util.Vector;
import javax.swing.*;
public class Registration{
     Vector studentVector;
public static void main(String args[]) {
     Registration regObj = new Registration();     
     Vector studentVector = new Vector();     
     regObj.inputStudent(studentVector); // input one student for modify to work     
     regObj.modifyStudent(studentVector,0); // edit student at element 0     
     Student studentObj = (Student)studentVector.get(0);
     System.out.println("**"+studentObj.getName());
public void inputStudent(Vector studentVectorTemp) {
     String inputName = null;
     String inputID = null;
     Student studentObj = null;
     while (inputName==null || !inputName.equals("end")) {
          inputName = JOptionPane.showInputDialog("Enter the name of the student");          
          if (inputName!=null && !inputName.equals("end")) {
               inputID = JOptionPane.showInputDialog("Enter the id of the student");
               studentObj = new Student(inputID,inputName);
               studentVectorTemp.add(studentObj);
public void modifyStudent(Vector studentVectorTemp, int whichStudent) {
     String inputName = null;
     String inputID = null;
     Student studentObj = null;
          inputName = JOptionPane.showInputDialog("Enter the name of "+whichStudent+"th student");
          inputID = JOptionPane.showInputDialog("Enter the id of "+whichStudent+"th student");
          if (studentVectorTemp!=null && studentVectorTemp.size()>whichStudent) {
               studentObj = (Student)studentVectorTemp.get(whichStudent);
               studentObj.setId(inputID);
               studentObj.setName(inputName);
               studentVectorTemp.set(whichStudent,studentObj);
* Do not use any gui in Student class
class Student{
private String id;
private String name;
public String getId() {
     return this.id;
public Student() {     
public Student(String id, String name) {
     super();
     this.id = id;
     this.name = name;
public void setId(String id) {
     this.id = id;
public String getName() {
     return this.name;
public void setName(String name) {
     this.name = name;
}Edited by: evilknighthk on Feb 13, 2008 6:43 PM

Similar Messages

  • I'm using TestStand/Labview to do a string value test. Is there any way to use a variable in the edit string value test?? This forces you to hard code a string to test against.

    I'm using TestStand 2.0/Labview 6i to do a string value test. Is there any way to use a string variable in the edit string value test instead of an actual string?? This forces you to hard code a string to test against.

    Hi ART,
    You can also use the LimitLoader step to load your string into to step similar to the Numeric Step type.
    There should be an example of this in the Resource Library | TestStand
    Regards
    Ray Farmer
    Regards
    Ray Farmer

  • How to edit an existing vector in perspektive tool

    Hello,
    as the topic says.
    How to edit an existing vector in perspektive tool
    Got an Domino Stone Vector and want to put in another perspective and dont know how!?
    Thx in advance for help

    Before putting complex art in perspective grid, ALWAYS create a symbol first.
    You can only rotate perspective layers (and the art) around the vanishing points. You cannot change perspective or move the vanishing points (at least not if you want to artwork to adapt to it).

  • Allow edit strings in constant pool + show index of constant pool items

    Please allow us to edit strings in constant pool and show the numeric index of constant pool items.

    Editing the strings in the constant pool takes some work since you have to re-adjust several length values throughout the SWF. However, SWF Investigator does show the index of the constant pool items in the disassembler tab.  Any time a constant is used, you will see " //nameIndex = #" at the end of the line. This number will represent the index of that constant in the constant pool.

  • Adding data from a vector into a JTable

    Hi,
    I've never used JTables before, so this is all new to me. I want to display the data I have in a vector in a JTable. The little I've read about doing this involves using arrays for the JTable information, and by using that as a guide I can't get it to work. A quick answer or perhaps a link to somewhere I can read up on it would be appreciated, thanks.

    Okay, thanks for the links. I was able to set up a table, and have it display the information I want it to....sorta. The problem is, the table is only showing the first element in my vector, and nothing else. Plus, when the table starts up, it's a small box in the corner of the screen and I have to click and drag to get it visible.
    Here's a bit of my code, perhaps someone could point out what's going wrong?
    //GUI class where I call the table class from
    //all GUI and even handling stuff up here
    else if(event.getSource() == listInven){
            sim.buildtable(vec3);
    //the table class
    public class table extends JFrame {
    public Vector vec3;
        String Type;
        Vector columnNames, rowData;
        JTable table2;
        public table(){
          super("Inventory");
          Type = "Type of product";
          columnNames = new Vector(1);
          rowData = new Vector(1);
        public void buildtable(Vector vec3){
            rowData.addElement(vec3);
            columnNames.addElement(Type);
            final JTable table2 = new JTable(rowData, columnNames);
            table2.setPreferredScrollableViewportSize(new Dimension(500, 70));
            JScrollPane scrollPane = new JScrollPane(table2);
            getContentPane().add(scrollPane, BorderLayout.CENTER);
            addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent e) {
                    System.exit(0);
            setVisible(true);
       }Any help is appreciated.

  • Adding/Editing ID3 Tags

    I've been assigned the task of helping faculty with iTunes U and have a question concerning ID3 Tags. Is there a way of adding/editing the ID3 tags of QT files outside of iTunes and before uploading the .mp4 files?
    Thanks
    Jerry

    Unfortunately Quicktime and iTunes store and access the metadata differently.
    You will need to ultimately edit your metadata via iTunes for use via iTunes U.
    Applescript or automator actions can save you a lot of effort.
    Check out Doug's applescripts for iTunes to learn more.

  • I created a vector and added objects, but the vector is empty

    I created an object called a facility, it accepts 2 strings in the creator but stores the data as a string and a float. as you can see from the code below, i have tried to create a vector object to contain facilitys and named it entries. when i add objects to this vector, the vectors size does not change, and i cannot access elements of it via their index. but when i print the vector out i can see the elements? what is going on here. i am very confused. ps, if it helps i havent worked with vectors much before.
    FacilitysTest.java
    import java.util.*;
    public class FacilitysTest {
         public static void main (String [] args) {
         Facilitys entries = new Facilitys();
         entries.add("Stage","3.56");
         entries.add("kitchen","5.00");
         entries.add("heating","2");
    //     System.out.println(entries.firstElement() );
         System.out.println("printing out entries");
         System.out.println(entries);
         System.out.println();
         System.out.println("There are "+entries.size()+" entries");
         System.out.println();
         System.out.println("modifying entry 2");
         entries.setElementAt(new Facility("lighting","1.34"), 2);
         System.out.println(entries);
         System.out.println();
         System.out.println("deleting entry 1");
         entries.remove(1);
         System.out.println(entries);
    }the following is what happens when i run this code.
    the number (0,1,2) is taken from a unique number assigned to the facility and is not anything to do with the facilitys position in the vector.
    printing out entries
    Facility number: 0, Name: Stage , Cost/Hour: 3.56
    Facility number: 1, Name: kitchen , Cost/Hour: 5.0
    Facility number: 2, Name: heating , Cost/Hour: 2.0
    There are 0 entries
    modifying entry 2
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2 >= 0
    at java.util.Vector.setElementAt(Vector.java:489)
    at FacilitysTest.main(FacilitysTest.java:17)
    Press any key to continue . . .
    Facilitys.java
    import java.util.*;
    public class Facilitys extends Vector {
         private Vector entries;
         public Facilitys( ) {
                 entries = new Vector();
        public void add( String name, String price ) {
             entries.add((new Facility( name, price) ));
        public Facility get(int index) {
              return ((Facility)entries.get(index));
         public float total() {
              float total = 0;
              for (int i = 0; i<entries.size();i++) {
                   total = total + ( (Facility)entries.get(i) ).getPricePerHour();
              return total;
        public String toString( ) {
            StringBuffer temp = new StringBuffer();
            for (int i = 0; i < entries.size(); ++i) {
                temp.append( entries.get(i).toString() + "\n" );
            return temp.toString();
    }

    are you reffering to where i have public class
    Facilitys extends Vector {
         private Vector entries;
         public Facilitys( ) {
                 entries = new Vector();
    That's correct. That's your problem.
    i added the extends Vector, because without it i got
    the following errors
    C:\Documents and Settings\george\My
    Documents\University\JavaCode\CM0112\FacilitysTest.jav
    a:14: cannot find symbol
    symbol : method size()
    location: class Facilitys
    System.out.println("There are "+entries.size()+"
    " entries");That's because you haven't implemented a size method in your class.
    ^
    C:\Documents and Settings\george\My
    Documents\University\JavaCode\CM0112\FacilitysTest.jav
    a:17: cannot find symbol
    symbol : method setElementAt(Facility,int)
    location: class Facilitys
    entries.setElementAt(new
    w Facility("lighting","1.34"), 2);That's because you haven't implemented setElementAt in your class.
    C:\Documents and Settings\george\My
    Documents\University\JavaCode\CM0112\FacilitysTest.jav
    a:21: cannot find symbol
    symbol : method remove(int)
    location: class Facilitys
         entries.remove(1);
    ^That's because you haven't implemented remove in your class.
    /Kaj

  • Adding query string to files already within shared documents

    Am a Sharepoint newbie, so hopefully this is an easy one. Am trying to add a query string to some hyperlinks (of PDF files) that are already published in a Shared Documents web part. What's the best way to accomplish this? Can't seem to find an easy
    way to edit the raw HTML anchor tag, which would be so simple. Is the anchor tag HTML exposed someplace where I can edit?
    Thanks in advance.

    You could potentially modify the rendering of a specific Shared Documents by modifying the XSL of your view in SharePoint Designer. However, this will not affect all libraries and not all views of the library, just the specific page.
    The jQuery method is actually very easy and can be deployed site-wide by adding a reference to your MasterPage, or to a specific view / page by using the Content Editor Web Part. The actual jQuery would look something like:
    $(document).ready(function() {
    $("a[href$='.pdf']").attr('href', function(i, v) {
    return v + '#YourCustomQueryString';
    Dimitri Ayrapetov (MCSE: SharePoint)

  • Converting int to string, adding to string then pointing to an url

    So I'm getting a null pointer exception here's a snippet of my code (theres plus signs on both sides of the a in my code):
    private Image[] tiles;
    public Map() {
    for(int a=0; a<9; a++){
    ImageIcon aa = new ImageIcon(this.getClass().getResource("mapsquares"+a+".png"));
    tiles[a] = aa.getImage();
    I've also tried:
    private Image[] tiles;
    public Map() {
    for(int a=0; a<9; a++){
    ImageIcon aa = new ImageIcon(this.getClass().getResource("mapsquares$s.png", String.valueOf(a)));
    tiles[a] = aa.getImage();
    whats wrong with either of these?
    Edited by: Wub on Feb 28, 2013 3:17 PM

    1.) You should use code tags when posting code.
    2.) You should read the stacktrace closely to find out which exact line number in your code threw the exception.
    My guess is that it's the line tiles[a] = aa.getImage(); because you didn't initialize the array tiles using the new operator. This is just a guess since you didn't post the full stacktrace. Also, NullpointerExceptions are one of the easiest to debug. Just adding print out lines at strategic values can show you which variables are initialized and which ones are not.

  • Editing 2-D vectors ??

    Hi all,
    I have a 2-dimensional vector of vectors of objects =). In order to edit an object in one of the vectors in the 2-d vector I do the following pseudocode. By the way I have replaced my actual object name with Object for you to read the code easily
    a = (Vector)vector2D.elementAt(index);
    a.add(new Object(/*some parameters*/));
    vector2D.setElementAt(a,index);
    However, this results in adding the new object to everyone of the vectors in the 2-D vector. This code is not in a for loop so the value of index is fixed.
    By the way, when i initialized vector2D I created a single non-empty vector of objects 'v' and kept adding it to the vector2D until the desired size was reached that is
    for (int i = 0; i <SIZE ; i++)
    vector2D.add(v);
    Can anyone see whats wrong with editing a 2 dimensional vector in this manner
    Regards
    Adil

    Please use ... tags, otherwise the forum will screw up the layout of your code.
    The problem is that your initialization loop puts multiple references to the same Vector (the one "v" points to) into every position of vector2D.

  • Adding new object to vector in existing session

    Hi,
    I'm currently developing a website. In it, the user can click a button(name=option,value=item) and an item gets added to a list. At the end, the list is outputted. I am having difficulties though with my session.
    My session("Item") holds a collection,basically a vector. Every time the button is pressed, I want to add a new object (Item) to this vector(ItemCollection) but when I do it simply overrides it so the list is only ever outputting one item. Here is the code. I have traced through it with 'System.out.print' and it only gets to 'System.out.println("session");
    The getItem(), gets the item from the database and returns a object of type Item.
    This may seem like only a basic thing but I just cant see where it is going wrong.
    Thanks
    else if(option.equals("item")){
                       System.out.println("ItemPressed");
                       String itemIdStr=request.getParameter("id");
                   int itemId=Integer.parseInt(itemIdStr);
                      ItemCollection list=new ItemCollection();
                       list=(ItemCollection)session.getAttribute("Item");
                       Item item=new Item();
                       Item itS=new Item();
                       System.out.println("getItem()");
                       itS=item.getItem(itemId);
                       System.out.println(itS.getItemName());
                       System.out.println("session");
                       list.addItem(itS);
                       session.setAttribute("Item",list);     
                    System.out.println("addedToSession");
                  }

    else if(option.equals("item")){
                    System.out.println("ItemPressed");
                    String itemIdStr=request.getParameter("id");
                   int itemId=Integer.parseInt(itemIdStr);
                   ItemCollection list=new ItemCollection();
                    list=(ItemCollection)session.getAttribute("Item");
                    Item item=new Item();
                    Item itS=new Item();
                    System.out.println("getItem()");
                    itS=item.getItem(itemId);
                    System.out.println(itS.getItemName());
                    System.out.println("session");
                    list.addItem(itS);
                    session.setAttribute("Item",list);     
                    System.out.println("addedToSession");
               }Maybe it's too early in the morning here, but it looks to me like you have all of your variables declared in your execution path....
    ... if that is the case, then uh... ya, they are going to be reinitalized each pass and only have at most the last item in them from your work.

  • Adding and Retriving of Vector through Hashtable

    Hi,
    I had a list of records from my database and I want to add it to my hashtable before passing it to another class to read. So I add my records into a vector before adding to a hashtable, but how do I read it out? Also how do I loop to store the vector in the hashtable?
    (WorkOrder is another class.)
    This is part of my code:
    String sql_GetOrder= "SELECT * FROM WORK_ORDER WHERE ORDER_ID = '043775122N' OR ORDER_ID = '077888862L'";
    rs = stmt.executeQuery(sql_GetOrder);
    result = new Vector();
    while (rs.next()){
    wOrder = new WorkOrder();
    wOrder.setOrderID(rs.getString("order_id"));
    wOrder.setCompanyBRN(rs.getString("brn"));
    wOrder.setSubmitBy(rs.getString("submit_by"));
    wOrder.setSubmitDate(rs.getString("submit_date"));
    System.out.println("Order ID: " + rs.getString("Order_id"));
    result.addElement(wOrder);
    myTable.put("cnt", wOrder);
    wOrder = null;                    
    System.out.println("My Vector Size: " + result.size()); 
    WorkOrder n = (WorkOrder)myTable.get("cnt");
         if (n != null) {
             System.out.println("cnt = " + n.getOrderID());
         } Thanks

    I can't do this way as you had mention:
    myTable.put(wOrder.getOrderID(), wOrder);I am passing my orders to another class and the orderid is unknown to the class, so how can the other class identfiy my key?
    I had done something like this:
    To put in the hashtable:
    String sql_GetOrder= "SELECT * FROM WORK_ORDER WHERE ORDER_ID = '043775122N'";
    rs = stmt.executeQuery(sql_GetOrder);
    result = new Vector();
    while (rs.next()){
    wOrder = new WorkOrder();
    wOrder.setOrderID(rs.getString("order_id"));
    System.out.println("Order ID: " + rs.getString("Order_id"));
    result.addElement(wOrder);
    wOrder = null;     
    if(result.size() > 0){
    System.out.println("My result Vector Size: " + result.size());
    listRecord = new Vector();
    listRecord.addElement(result);
    System.out.println("My listRecord Vector Size: " + listRecord.size());
    myTable.put("cnt", listRecord);
    }To get from hashtable:
    if(!dTable.isEmpty())
    Vector vList = (Vector)dTable.get("cnt");
    Vector readList = new Vector();
    if (vList != null) {
    readList = (Vector)vList.get(0);
    for (int i=0; i<readList.size(); i++){
    WorkOrder w_order = new WorkOrder();
    w_order = (WorkOrder)readList.get(i);
    System.out.println("cnt = " + w_order.getOrderID());

  • ADDING DATA TO JAVA VECTOR

    Hi,
    We try to add data in forms 9.0.4 to java string vector, but i don't know make.
    This my code: But doesn't work.
    declare
         vector      ora_java.jobject;
         javadate      ora_java.jobject;
    begin
         vector := ora_java.new_string_array(2);
         ora_java.set_string_array_element(vector,0,'dato_1');
         ora_java.set_string_array_element(vector,1,'dato_2');
         javadate.add_vector(vector);
    end;
    thank for all.

    Add an exception handler to get an error message.
    EXCEPTION
    WHEN ORA_JAVA.JAVA_ERROR then
      message('Unable to call out to Java, ' ||ORA_JAVA.LAST_ERROR);
    WHEN ORA_JAVA.EXCEPTION_THROWN then
      ex := ORA_JAVA.LAST_EXCEPTION;
      message(Exception.getMessage(ex));

  • Inserting a clip at the beginning of a edited string of clips?

    I have five clips edited together. I need to put one more clip at the beginning of the string. Is there a way to move an entire string of clips forward all at once so that I can slip the clip in? Hope this makes sense?

    What CC and Ann recommended is right on the money for your immediate goal of inserting a clip before clips that are already in the timeline. But there will be other occasions when you want to select multiple track items. There are several ways to do so:
    To select all track items before or after a given point, select the Track Select Backward or Track Select Forward tool and click the timeline. Those tools select clips on all tracks; if you want to isolate a single track, hold SHIFT while clicking.
    With the Selection tool active [V]: click a blank spot in the timeline and drag across the desired clips. This is called "marquee selection." By the way, if you do this with the Ripple Edit or Rolling Edit tool active, the edit points between clips will be selected rather than the clips themselves.
    Also with the Selection tool, shift-click the track items. This is the best method when the clips you want select are intermixed with others that you want to leave unselected.

  • Array of strings to vector

    Hi,
    I have an array of strings like:
    private String myStrArr[];
    myStrArr = new String[256];
    I have to get rid of hard coded size.
    Is it ok to use vector instead , or is there another way to get rid of hard coded size.
    If we can use vector instead , is there a solution similar for booleans??
    I also have an array of booleans:
    private boolean myBoolArr[];
    myBoolArr = new boolean[256]

    You can wrap the primitive booleans you have in the Boolean class via
    myList.add(new Boolean(primitiveBooleanValue));Even better, to save space, use the already existing Boolean values instead of creating new ones. If you are using Java 1.4, you can:
    myList.add(Boolean.valueOf(primitiveBooleanValue));Otherwise you can do one of these:
    myList.add( primitiveBooleanValue ? Boolean.TRUE : Boolean.FALSE );

Maybe you are looking for

  • When I get attachments in my email, they will not open when I click on them.

    When I am on the internet, videos, click-ons all open immediately. I had to go to the internet to get to your site, because when I clicked on the "Help" at the bottom of my Thunderbird account, it would not open. In a nutshell, if I get an email from

  • HP 3180 All-in-one will print test page but nothing else

    Hi, I have a HP 3180 All-in-one connected to my desktop PC which runs on Vista OS.  The printer seems to be perfectly happy to print a test page but with all other documents it feeds the paper as though it's getting ready to print, then the cartridge

  • Error 0x8007000E-0x2000C in upgrade from 7 pro to 8.1 pro

    Issue with error on  upgrade from 7 pro to 8.1 pro of error 0x8007000E-0x2000C.  I have tried the install several times and this error returns every time.

  • AC3 sounds garbled when played back through the asset window

    i have a 5.1 AC3 file i made with A.Pack with DVDSP3 (now using DVDSP4) and when i played the file back in my asset window via S/PDIF out on the Mac to a Dolby Digital Capable 5.1 amp (having the prefs in DVDSP set to SPDIF not default in the simulat

  • How much functionality in constructor?

    Hi Lets say I have a class 'schedule' which builds a schedule from a set of data and then holds that schedule for further processing. Which of these two options is better designed?: public class Schedule      public Schedule(SomeInputs inputs)