473,466 Members | 1,397 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

What is the difference between an array and arraylist in java?Also specify the differ

5 New Member
What is the difference between an array and arraylist in java?Also specify the difference between a String and StringBuffer?
Dec 6 '06 #1
2 7567
DeMan
1,806 Top Contributor
An array is pretty much the same as in any other language, and ArrayList is a linked list (sort of a dynamic array).

It's (and most container classes) methods include:
add(Object o) //add element to rear of list
add(Object o, int i) //add element o at ith position
addAll(Container c) //add all elements in another container element
addAll(Object[] o) //add all objects in array
get(int i) //get object at ith position
remove(int i) //get object at ith position and remove it from the list
lot's more....look it up

The beauty is, you don't have to worry about the size, it is dynamic.
If you remove the ith element, the (i+1)th element becomes the ith and everything moves down (well it actually doesn't but it appears to to the user)

Not sure on the String/StringBuffer....I think the StringBuffer allows more manipulation and (if memory serves me correct) a StringBuffer is an actual object whereas a String just pretends to be. Specifically, if you try to manipulate a String you keep creating new Strings (of different lengths and with different values), while the StringBuffer actually manipulates the actual String you are playing wiht (someone will undoubtedly correct me if I'm wrong....)
Dec 6 '06 #2
r035198x
13,262 MVP
An array is pretty much the same as in any other language, and ArrayList is a linked list (sort of a dynamic array).

It's (and most container classes) methods include:
add(Object o) //add element to rear of list
add(Object o, int i) //add element o at ith position
addAll(Container c) //add all elements in another container element
addAll(Object[] o) //add all objects in array
get(int i) //get object at ith position
remove(int i) //get object at ith position and remove it from the list
lot's more....look it up

The beauty is, you don't have to worry about the size, it is dynamic.
If you remove the ith element, the (i+1)th element becomes the ith and everything moves down (well it actually doesn't but it appears to to the user)

Not sure on the String/StringBuffer....I think the StringBuffer allows more manipulation and (if memory serves me correct) a StringBuffer is an actual object whereas a String just pretends to be. Specifically, if you try to manipulate a String you keep creating new Strings (of different lengths and with different values), while the StringBuffer actually manipulates the actual String you are playing wiht (someone will undoubtedly correct me if I'm wrong....)
Quite on track DeMan only that a String is actually an object as well (no pretence).
If any be interested in using StrinBuffer these days, they are advised to check StringBuilder first.
Dec 6 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Andrew Dixon - Depictions.net | last post by:
Hi Everyone. Bit new to Java and I have question about arrays. I have wrote some code to look for certain substrings within a larger string which work fine. I would like to store each substring...
4
by: Naresh Agarwal | last post by:
Hi What are the different kinds of JVMs exist and in what respect do they differ. What is the difference between client, server, classic and hotspot jvms? thanks, Naresh
3
by: Jack Addington | last post by:
Quite new to C# but I am getting quite confused with Array's and ArrayLists. This is probably the same old iteration of a basic question but I can't seem to find a clear answer/example of this...
13
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
24
by: RyanTaylor | last post by:
I have a final coming up later this week in my beginning Java class and my prof has decided to give us possible Javascript code we may have to write. Problem is, we didn't really cover JS and what...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
38
by: Zytan | last post by:
What is the difference between these two lines? Dim args As Object() = New Object() {strText} Dim args As Object() = {strText} args seems usuable from either, say, like so: ...
1
by: stevedub | last post by:
I am having some trouble configuring my array to read from a sequential file, and then calling on that to fill an array of interests. I think I have the class set up to read the file, but when I run...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.