Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 746271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:04:18+00:00 2026-05-14T14:04:18+00:00

I was reading a Java article, but found no differences in the declaration and

  • 0

I was reading a Java article, but found no differences in the declaration and was confused over. Can anyone list me out this?

Added the Article

http://www.theparticle.com/javadata2.html

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T14:04:19+00:00Added an answer on May 14, 2026 at 2:04 pm

    Without more details as to what the question is exactly asking, I am going to answer the title of the question,

    Create an Array:

    String[] myArray = new String[2];
    int[] intArray = new int[2];
    
    // or can be declared as follows
    String[] myArray = {"this", "is", "my", "array"};
    int[] intArray = {1,2,3,4};
    

    Create an ArrayList:

    ArrayList<String> myList = new ArrayList<String>();
    myList.add("Hello");
    myList.add("World");
    
    ArrayList<Integer> myNum = new ArrayList<Integer>();
    myNum.add(1);
    myNum.add(2);
    

    This means, create an ArrayList of String and Integer objects. You cannot use int because thats a primitive data types, see the link for a list of primitive data types.

    Create a Stack:

    Stack myStack = new Stack();
    // add any type of elements (String, int, etc..)
    myStack.push("Hello");
    myStack.push(1);
    

    Create an Queue: (using LinkedList)

    Queue<String> myQueue = new LinkedList<String>();
    Queue<Integer> myNumbers = new LinkedList<Integer>();
    myQueue.add("Hello");
    myQueue.add("World");
    myNumbers.add(1);
    myNumbers.add(2);
    

    Same thing as an ArrayList, this declaration means create an Queue of String and Integer objects.


    Update:

    In response to your comment from the other given answer,

    i am pretty confused now, why are using string. and what does <String> means

    We are using String only as a pure example, but you can add any other object, but the main point is that you use an object not a primitive type. Each primitive data type has their own primitive wrapper class, see link for list of primitive data type’s wrapper class.

    I have posted some links to explain the difference between the two, but here are a list of primitive types

    • byte
    • short
    • char
    • int
    • long
    • boolean
    • double
    • float

    Which means, you are not allowed to make an ArrayList of integer’s like so:

    ArrayList<int> numbers = new ArrayList<int>(); 
               ^ should be an object, int is not an object, but Integer is!
    ArrayList<Integer> numbers = new ArrayList<Integer>();
                ^ perfectly valid
    

    Also, you can use your own objects, here is my Monster object I created,

    public class Monster {
       String name = null;
       String location = null;
       int age = 0;
    
    public Monster(String name, String loc, int age) { 
       this.name = name;
       this.loc = location;
       this.age = age;
     }
    
    public void printDetails() {
       System.out.println(name + " is from " + location +
                                         " and is " + age + " old.");
     }
    } 
    

    Here we have a Monster object, but now in our Main.java class we want to keep a record of all our Monster‘s that we create, so let’s add them to an ArrayList

    public class Main {
        ArrayList<Monster> myMonsters = new ArrayList<Monster>();
    
    public Main() {
        Monster yetti = new Monster("Yetti", "The Mountains", 77);
        Monster lochness = new Monster("Lochness Monster", "Scotland", 20);
    
        myMonsters.add(yetti); // <-- added Yetti to our list
        myMonsters.add(lochness); // <--added Lochness to our list
      
        for (Monster m : myMonsters) {
            m.printDetails();
         }
       }
    
    public static void main(String[] args) {
        new Main();
     }
    }
    

    (I helped my girlfriend’s brother with a Java game, and he had to do something along those lines as well, but I hope the example was well demonstrated)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was reading an article on handling Out Of Memory error conditions in Java
I am reading the Java Hashmap documentation but I don't understand this sentence. Note
I was reading an article on Batch Processing in java over at JDJ http://java.sys-con.com/node/415321
I was looking at using Amazon's EC2 service after reading this article: http://www.ibm.com/developerworks/java/library/j-javadev2-4/index.html But
I recall reading an article about constructors being evil (but can't place it). The
Reading this DZone article about Java concurrency I was wondering if the following code:
Right now I'm reading this article regarding Java Garbage Collection: http://www.javaworld.com/javaworld/jw-08-1996/jw-08-gc.html ? Here is
I was reading this article about Double-Checked locking and out of the main topic
Reading Java Concurrency In Practice, there's this part in section 3.5: public Holder holder;
I am reading Java Virtual Machine Specification second edition for Java 6. But I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.