0% found this document useful (0 votes)
25 views2 pages

2011cs155 Re

Variables store information during a program's execution and can change value. Arrays store a list of items of the same type and allow indexed access. Vectors are like dynamic arrays that expand automatically when new data is added, holding objects but not primitives, and are generally faster to create with an initial size.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views2 pages

2011cs155 Re

Variables store information during a program's execution and can change value. Arrays store a list of items of the same type and allow indexed access. Vectors are like dynamic arrays that expand automatically when new data is added, holding objects but not primitives, and are generally faster to create with an initial size.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Different between Variable,Array and Vector

Variables
A variable is a place where information can be stored while a program is running. The value can be changed at any point in the programhence the name. To create a variable, you must give it a name and identify what type of information it will store. You also can give a variable an initial value at the same time you create it.

Arrays
Arrays are a way to store a list of items that have the same primitive data type, the same class, or a common parent class. Each item on the list goes into its own numbered slot so that you can easily access the information. Arrays can contain any type of information that is stored in a variable, but after the array is created, you can use it for that information type only. For example, you can have an array of integers, an array of string objects, or an array of arrays, but you cant have an array that contains both string objects and integers.

Vectors
Vectors (the java.util.Vector class) are commonly used instead of arrays, because they expand automatically when new data is added to them. Vectors can hold only Objects and not primitive types (eg, int). If you want to put a primitive type in a Vector, put it inside an object (eg, to save an integer value use the Integer class or define your own class). If you use the Integer wrapper, you will not be able to change the integer value, so it is sometimes useful to define your own class. To Create a Vector ,You must import either import java.util.Vector; or import java.util.*;.Vectors are implemented with an array, and when that array is full and an additional element is added, a new array must be allocated. Because it takes time to create a bigger array and copy the elements from the old array to the new array, it is a little faster to create a Vector with a size that it will commonly be when full. Of course, if you knew the final size, you could simply use an array. However, for non-critical sections of code programmers typically don't specify an initial size. Create a Vector with default initial size Vector v = new Vector(); Create a Vector with an initial size Vector v = new Vector(300);

public class d{ public static void main(String [] args){ for (int i=0; i<4; i++){ for (int j=0; j<4; j++){ if((i>0&i<3)&(j>0&j<3)) System.out.print(" "); else System.out.print("*"); } System.out.println(" "); } } }

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy