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

  • Home
  • SEARCH
  • 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

Ask A Question

Stats

  • Questions 489k
  • Answers 489k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Why not use LINQ to Entities instead? context.Spells.Where(s => s.ID.Equals(1)); May 16, 2026 at 8:50 am
  • Editorial Team
    Editorial Team added an answer You can't do this reliably. The reason is simple: everything… May 16, 2026 at 8:50 am
  • Editorial Team
    Editorial Team added an answer The Windows Azure billing model today focuses on billing the… May 16, 2026 at 8:50 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

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 was reading an article on Batch Processing in java over at JDJ http://java.sys-con.com/node/415321
I was reading this article today on two different regular expression algorithms. According to
According to this Wikipedia article , you are allowed 3,000 files per app but
I've been reading this article about closures in which they say: all the plumbing
I was just reading an article that showed the following Spring Security XML configuration:
I was reading some things about exception handling in Java, to be able to
After reading this answer: best way to pick a random subset from a collection?
I recently read the excellent article The Transactional Memory / Garbage Collection Analogy by
This question is a continuation of my previous question here zend models architecture (big

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.