Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: adding varibles to array and using Jlist

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default adding varibles to array and using Jlist

    Hello
    i want to add some variables to an array and i want to use for loop beacuase I have 500 varibles and i cant do this
    names[350] = var;
    names[351] = var;
    names[352] = var;
    names[353] = var;

    this will take 500 lines so i want to use a for loop but i don't know how to add each variable to an element of the array.
    private void List() {
     
            String one = "Hello", two = "How", three = "Are", four = "You";
     
            String[] names = new String[4];
     
            names[0] = one;
            names[1] = two;
            names[2] = three;
            names[3] = four;
     
            /*    
            for(int i=0; i<names.length; i++) {
                names[i] += one;
                names[i] += two;
                names[i] += three;
                names[i] += four;
            }*/
     
            JList list = new JList(names);
            list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            list.setSize(100, 100);
            list.setLocation(100, 100);
            ContentPane.add(list);
        }


  2. #2
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: adding varibles to array and using Jlist

    i want to add some variables to an array and i want to use for loop beacuase I have 500 varibles and i cant do this
    I assume you mean the value of variables. Are variables given or you will have to create on your own?
    From where is the value assigning to these variables?

Similar Threads

  1. Adding to Array from JavaSpace problem
    By rtumatt in forum Collections and Generics
    Replies: 2
    Last Post: September 15th, 2011, 08:11 AM
  2. Adding strings to an array dynamically, how can i do it?
    By emkoirl in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 8th, 2011, 03:07 PM
  3. [SOLVED] adding to a multidimensional array.
    By Scotty in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 27th, 2011, 11:09 AM
  4. Adding to Array from JavaSpace problem
    By rtumatt in forum Collections and Generics
    Replies: 3
    Last Post: January 5th, 2010, 07:19 PM
  5. Java operaton on boolean varibles
    By big_c in forum Java Theory & Questions
    Replies: 5
    Last Post: May 12th, 2009, 05:40 AM