string array help (eg edit, delete, add, etc..) java

Discussion in 'Java' started by belial, Oct 16, 2011.

  1. belial

    belial New Member

    Joined:
    Oct 14, 2011
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    program that calls data from an external txt file.....i already have code for reading then sorting the items by their various categories (costP, desc, stockqty, etc) wen i sort one string the others are sorted
    however i have nooo idea how to add or remove values to the strings.....i need to be able to search and delete an item from one category and all corresponding values or data on this item will be removed from other strings as well (corresponding items are sorted in parallel) and wen i add an item i need to get the option to add all its corresponding values!! any help will be appreciated thanks...


    Code:
    public class PD
    {
    
        final static int max = 100; //Arr Size
    
        public static Scanner keyboard;
       
        //Arr initialisations
        public static String catList[] = new String[max];
        public static String prodCodeList[] = new String[max];
        public static String desList[] = new String[max];
        public static float costPList[] = new float[max];
        public static float sellPList[] = new float[max];
        public static int qtySkList[] = new int[max];
        public static int qtySdList[] = new int[max];
        public static int reLevList[] = new int[max];
        //public static int holder[] = new int [max];
       
        public static int count;// arr counter
    
        public static void main(String args[]) 
    {
    
            keyboard = new Scanner(System.in);
            int response = 0;
    
            loadInput();//Load data from input file
    
    do {
                response = mainMenu();
                if (response == 1)
                {
                    response = sortMenu();// response 1 an 2 sorts in asc an desc order resp...already did this
                    if (response == 1)
                    {   i already wrote the code to sort all the data by anything depending on  what option the user wants
                     }
    
    if (response == 3)// Add a values to arrays
                {  i really need help here adding values to the string arrays
                 }
    if (response == 4)// delete values
                { need help here as well
                 }
    if (response == 5)// Update information existing in strings
                { i think i would have to use stringbuffer in this case
                 }
     
    Last edited by a moderator: Oct 17, 2011
  2. belial

    belial New Member

    Joined:
    Oct 14, 2011
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    ok so i did this to add an element but all it does is replace the last value in the catList with the typed string and adds null values to a new string after the last one...

    public static String addcatListElement()
    {
    System.out.println("Enter category of new part>");
    catList[count++] = keyboard.next();
    count++;
    return categoryList[count];
    }
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice