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: ArrayList woes

  1. #1
    Junior Member
    Join Date
    Nov 2024
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default ArrayList woes

    I'm not sure what is wrong with rows (6) and (12). I moved the code out of the main method which I enjoy.
    import java.util.ArrayList;
     
    public class P133_ArrayList {
        public static void main(String Args[]){
            P133_ArrayList ar = new P133_ArrayList();
            ar.run();  //expected class or package
        }
     
        class run {
            ArrayList<Egg> myList = new ArrayList<Egg>();
            Egg egg1 = new Egg();
            myList.add(Egg1);  //cannot resolve symbol Egg1
     
            Egg egg2 = new Egg();
            myList.add(Egg2);
     
            Egg egg3 = new Egg();
            myList.add(Egg3);
     
            int theSize = myLIst.size();
     
            boolean isIn = myList.contains(egg1);
     
            int idx = myLIst.indexOf(egg2);
     
            boolean empty= mylist.isEmpty();
     
            myList.remove(egg1);
     
        }
     
         class Egg{
            String speak = "Cluck Cluck";
        }
    }

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: ArrayList woes

    I'm not sure what is wrong
    Java is case sensitive: E is different from e

    class run {
    Looks like you intended run to be a method, not a class. Change that line to:
    private void run() {
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Exception handling woes
    By ineedahero in forum What's Wrong With My Code?
    Replies: 13
    Last Post: September 24th, 2013, 08:51 AM
  2. Printf syntax woes
    By ineedahero in forum What's Wrong With My Code?
    Replies: 2
    Last Post: September 21st, 2013, 09:14 AM
  3. Replies: 0
    Last Post: March 11th, 2012, 04:57 PM
  4. [SOLVED] Dialog Woes...
    By snowguy13 in forum AWT / Java Swing
    Replies: 1
    Last Post: February 25th, 2012, 09:08 PM