Parameter list object java

Class ArrayList

Type Parameters: E — the type of elements in this list All Implemented Interfaces: Serializable , Cloneable , Iterable , Collection , List , RandomAccess Direct Known Subclasses: AttributeList , RoleList , RoleUnresolvedList

Resizable-array implementation of the List interface. Implements all optional list operations, and permits all elements, including null . In addition to implementing the List interface, this class provides methods to manipulate the size of the array that is used internally to store the list. (This class is roughly equivalent to Vector , except that it is unsynchronized.)

The size , isEmpty , get , set , iterator , and listIterator operations run in constant time. The add operation runs in amortized constant time, that is, adding n elements requires O(n) time. All of the other operations run in linear time (roughly speaking). The constant factor is low compared to that for the LinkedList implementation.

Each ArrayList instance has a capacity. The capacity is the size of the array used to store the elements in the list. It is always at least as large as the list size. As elements are added to an ArrayList, its capacity grows automatically. The details of the growth policy are not specified beyond the fact that adding an element has constant amortized time cost.

An application can increase the capacity of an ArrayList instance before adding a large number of elements using the ensureCapacity operation. This may reduce the amount of incremental reallocation.

Note that this implementation is not synchronized. If multiple threads access an ArrayList instance concurrently, and at least one of the threads modifies the list structurally, it must be synchronized externally. (A structural modification is any operation that adds or deletes one or more elements, or explicitly resizes the backing array; merely setting the value of an element is not a structural modification.) This is typically accomplished by synchronizing on some object that naturally encapsulates the list. If no such object exists, the list should be «wrapped» using the Collections.synchronizedList method. This is best done at creation time, to prevent accidental unsynchronized access to the list:

List list = Collections.synchronizedList(new ArrayList(. ));

The iterators returned by this class’s iterator and listIterator methods are fail-fast: if the list is structurally modified at any time after the iterator is created, in any way except through the iterator’s own remove or add methods, the iterator will throw a ConcurrentModificationException . Thus, in the face of concurrent modification, the iterator fails quickly and cleanly, rather than risking arbitrary, non-deterministic behavior at an undetermined time in the future.

Читайте также:  Html color code coding

Note that the fail-fast behavior of an iterator cannot be guaranteed as it is, generally speaking, impossible to make any hard guarantees in the presence of unsynchronized concurrent modification. Fail-fast iterators throw ConcurrentModificationException on a best-effort basis. Therefore, it would be wrong to write a program that depended on this exception for its correctness: the fail-fast behavior of iterators should be used only to detect bugs.

This class is a member of the Java Collections Framework.

Источник

How to Pass ArrayList Object as Function Argument in java?

ArrayList class in Java is basically a resizable array i.e. it can grow and shrink in size dynamically according to the values that we add or remove to/from it. It is present in java.util package. If we want to pass an ArrayList as an argument to a function then we can easily do it using the syntax mentioned below.

ArrayList list = new ArrayList<>(); modifyList(list); public static void modifyList(ArrayList list)

In the code above, we created an ArrayList object named ‘list’ and then we passed it to a function named modifyList. The changes that we did to this list (i.e. the values that we added to the list) will appear to the original list inside the main function. This is happening because the Object References are passed by value in java as java is strictly Pass by Value.

Implementation of the problem statement:

Java

ArrayList after insertions: [3, 57, 7] ArrayList after modifications: [3, 57, 7, 20, 98]

How Java is pass by Value?

Let us assume that the Array list object that we created inside the main function points to an address 1000. When we passed this object to the modifyList function then the address 1000 is passed to it and the object ‘parameterList’ also starts pointing to the same location inside the memory as that of ‘list’ that is why we said that object references are passed by value in java. After that when we did modifications to ‘parameterList’ then the same changes are made to the original ‘list’. This concept is very similar to what happens in C++ when we pass a pointer variable as an argument.

ArrayList list = new ArrayList<>(); callByValue(list); public static void callByValue(ArrayList parameterList)< parameterList = new ArrayList<>(); parameterList.add(88); parameterList.add(200); parameterList.add(89); >

In the code above when we passed the list to the callByValue function then the ‘parameterList’ starts pointing to the memory address i.e. 1000. But when we created a new instance of ArrayList and made ‘parameterList’ point to it then ‘parameterList’ starts pointing to a new memory address (let’s say) 2000. The changes made to ArrayList inside this function will no longer affect the ArrayList at memory address 1000. Hence, the ‘list’ inside the main function remains unaffected.

Below is the implementation of the problem statement:

Источник

Parameter list object java

This class holds MIME parameters (attribute-value pairs). The mail.mime.encodeparameters and mail.mime.decodeparameters System properties control whether encoded parameters, as specified by RFC 2231, are supported. By default, such encoded parameters are not supported.

Also, in the current implementation, setting the System property mail.mime.decodeparameters.strict to «true» will cause a ParseException to be thrown for errors detected while decoding encoded parameters. By default, if any decoding errors occur, the original (undecoded) string is used.

The current implementation supports the System property mail.mime.parameters.strict , which if set to false when parsing a parameter list allows parameter values to contain whitespace and other special characters without being quoted; the parameter value ends at the next semicolon. If set to true (the default), parameter values are required to conform to the MIME specification and must be quoted if they contain whitespace or special characters.

Author: John Mani, Bill Shannon

Constructor Summary
ParameterList ()
No-arg Constructor.
ParameterList (java.lang.String s)
Constructor that takes a parameter-list string.
Method Summary
java.lang.String get (java.lang.String name)
Returns the value of the specified parameter.
java.util.Enumeration getNames ()
Return an enumeration of the names of all parameters in this list.
void remove (java.lang.String name)
Removes the specified parameter from this ParameterList.
void set (java.lang.String name, java.lang.String value)
Set a parameter.
void set (java.lang.String name, java.lang.String value, java.lang.String charset)
Set a parameter.
int size ()
Return the number of parameters in this list.
java.lang.String toString ()
Convert this ParameterList into a MIME String.
java.lang.String toString (int used)
Convert this ParameterList into a MIME String.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

ParameterList


ParameterList

Constructor that takes a parameter-list string. The String is parsed and the parameters are collected and stored internally. A ParseException is thrown if the parse fails. Note that an empty parameter-list string is valid and will be parsed into an empty ParameterList.

Parameters: s — the parameter-list string. Throws: ParseException — if the parse fails.

Method Detail

size

Returns: number of parameters.

get

public java.lang.String get(java.lang.String name)

Parameters: name — parameter name. Returns: Value of the parameter. Returns null if the parameter is not present.

set

public void set(java.lang.String name, java.lang.String value)

Parameters: name — name of the parameter. value — value of the parameter.

set

public void set(java.lang.String name, java.lang.String value, java.lang.String charset)

Set a parameter. If this parameter already exists, it is replaced by this new value. If the mail.mime.encodeparameters System property is true, and the parameter value is non-ASCII, it will be encoded with the specified charset, as specified by RFC 2231.

Parameters: name — name of the parameter. value — value of the parameter. charset — charset of the parameter value. Since: JavaMail 1.4

remove

public void remove(java.lang.String name)

Removes the specified parameter from this ParameterList. This method does nothing if the parameter is not present.

Parameters: name — name of the parameter.

getNames

public java.util.Enumeration getNames()

Returns: Enumeration of all parameter names in this list.

toString

public java.lang.String toString()

Convert this ParameterList into a MIME String. If this is an empty list, an empty string is returned.

Overrides: toString in class java.lang.Object Returns: String

toString

public java.lang.String toString(int used)

Convert this ParameterList into a MIME String. If this is an empty list, an empty string is returned. The ‘used’ parameter specifies the number of character positions already taken up in the field into which the resulting parameter list is to be inserted. It’s used to determine where to fold the resulting parameter list.

Parameters: used — number of character positions already used, in the field into which the parameter list is to be inserted. Returns: String

Overview Package Class Tree Deprecated Index Help
PREV CLASS NEXT CLASS FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD DETAIL: FIELD | CONSTR | METHOD
Submit a bug or feature

Copyright © 2009-2011, Oracle Corporation and/or its affiliates. All Rights Reserved. Use is subject to license terms.

Generated on 10-February-2011 12:41

Источник

Оцените статью