Copies the given array and adds the given element at the end of the new array.(double type value) : Array Insert Remove « Collections Data Structure « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Class
8. Collections Data Structure
9. Data Type
10. Database SQL JDBC
11. Design Pattern
12. Development Class
13. EJB3
14. Email
15. Event
16. File Input Output
17. Game
18. Generics
19. GWT
20. Hibernate
21. I18N
22. J2EE
23. J2ME
24. JDK 6
25. JNDI LDAP
26. JPA
27. JSP
28. JSTL
29. Language Basics
30. Network Protocol
31. PDF RTF
32. Reflection
33. Regular Expressions
34. Scripting
35. Security
36. Servlets
37. Spring
38. Swing Components
39. Swing JFC
40. SWT JFace Eclipse
41. Threads
42. Tiny Application
43. Velocity
44. Web Services SOA
45. XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java » Collections Data Structure » Array Insert RemoveScreenshots 
Copies the given array and adds the given element at the end of the new array.(double type value)
   

/*   Copyright 2004 The Apache Software Foundation
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *  limitations under the License.
 */


import java.lang.reflect.Array;


/**
 * <p>Operations on arrays, primitive arrays (like <code>int[]</code>) and
 * primitive wrapper arrays (like <code>Integer[]</code>).</p>
 
 * <p>This class tries to handle <code>null</code> input gracefully.
 * An exception will not be thrown for a <code>null</code>
 * array input. However, an Object array that contains a <code>null</code>
 * element may throw an exception. Each method documents its behaviour.</p>
 *
 @author Stephen Colebourne
 @author Moritz Petersen
 @author <a href="mailto:fredrik@westermarck.com">Fredrik Westermarck</a>
 @author Nikolay Metchev
 @author Matthew Hawthorne
 @author Tim O'Brien
 @author Pete Gieser
 @author Gary Gregory
 @author <a href="mailto:equinus100@hotmail.com">Ashwin S</a>
 @author Maarten Coene
 @since 2.0
 @version $Id: ArrayUtils.java 632503 2008-03-01 00:21:52Z ggregory $
 */
public class Main {
  
  
  /**
   * <p>Copies the given array and adds the given element at the end of the new array.</p>
   *
   * <p>The new array contains the same elements of the input
   * array plus the given element in the last position. The component type of 
   * the new array is the same as that of the input array.</p>
   *
   * <p>If the input array is <code>null</code>, a new one element array is returned
   *  whose component type is the same as the element.</p>
   
   * <pre>
   * ArrayUtils.add(null, 0)   = [0]
   * ArrayUtils.add([1], 0)    = [1, 0]
   * ArrayUtils.add([1, 0], 1) = [1, 0, 1]
   * </pre>
   
   @param array  the array to copy and add the element to, may be <code>null</code>
   @param element  the object to add at the last index of the new array
   @return A new array containing the existing elements plus the new element
   @since 2.1
   */
  public static double[] add(double[] array, double element) {
      double[] newArray = (double[])copyArrayGrow1(array, Double.TYPE);
      newArray[newArray.length - 1= element;
      return newArray;
  }

  
  /**
   * Returns a copy of the given array of size 1 greater than the argument. 
   * The last value of the array is left to the default value.
   
   @param array The array to copy, must not be <code>null</code>.
   @param newArrayComponentType If <code>array</code> is <code>null</code>, create a 
   * size 1 array of this type.
   @return A new copy of the array of size 1 greater than the input.
   */    
  private static Object copyArrayGrow1(Object array, Class newArrayComponentType) {
      if (array != null) {
          int arrayLength = Array.getLength(array);
          Object newArray = Array.newInstance(array.getClass().getComponentType(), arrayLength + 1);
          System.arraycopy(array, 0, newArray, 0, arrayLength);
          return newArray;
      }
      return Array.newInstance(newArrayComponentType, 1);
  }


}

   
    
    
  
Related examples in the same category
1. Adds all the elements of the given arrays into a new boolean-value array.
2. Adds all the elements of the given arrays into a new byte-type array.
3. Adds all the elements of the given arrays into a new char-type array.
4. Adds all the elements of the given arrays into a new double-type array.
5. Adds all the elements of the given arrays into a new float-type array.
6. Adds all the elements of the given arrays into a new int-type array.
7. Adds all the elements of the given arrays into a new long-type array.
8. Adds all the elements of the given arrays into a new short-type array.
9. Copies the given array and adds the given element at the end of the new array. (char type value)
10. Copies the given array and adds the given element at the end of the new array. (float type value)
11. Copies the given array and adds the given element at the end of the new array. (long value type)
12. Copies the given array and adds the given element at the end of the new array. (object value type)
13. Copies the given array and adds the given element at the end of the new array.(boolean value type)
14. Copies the given array and adds the given element at the end of the new array.(byte value type)
15. Copies the given array and adds the given element at the end of the new array.(int value type)
16. Copies the given array and adds the given element at the end of the new array.(short type array)
17. Inserts the specified element at the specified position in the array.
18. Inserts the specified element at the specified position in the boolean-type-value array.
19. Inserts the specified element at the specified position in the byte-type-value array.
20. Inserts the specified element at the specified position in the char-type-value array.
21. Inserts the specified element at the specified position in the double-type-value array.
22. Inserts the specified element at the specified position in the float-value-type array.
23. Inserts the specified element at the specified position in the int-type-value array.
24. Inserts the specified element at the specified position in the long-type-value array.
25. Inserts the specified element at the specified position in the short-value-type array.
26. Removes the element at the specified position from the specified array.
27. Removes the element at the specified position from the specified long type array.
28. Removes the first occurrence of the specified element from the specified array.
29. Removes the first occurrence of the specified element from the specified long value array.
30. Insert value to array
31. Array Copy Utilities
32. Concatenate Java arrays
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.