Insert value to array : 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 
Insert value to array
   


/*
 * dbXML - Native XML Database
 * Copyright (C) 1999-2004  The dbXML Group, L.L.C.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * $Id: Array.java,v 1.2 2004/02/12 00:17:58 bradford Exp $
 */

/**
 * Array utility methods
 */

public final class Array {
   private Array() {
   }

   public static Object[] insertArrayObject(Object[] vals, Object val, int idx) {
      Object[] newVals = new Object[vals.length + 1];
      if idx > )
         System.arraycopy(vals, 0, newVals, 0, idx);
      newVals[idx= val;
      if idx < vals.length )
         System.arraycopy(vals, idx, newVals, idx + 1, vals.length - idx);
      return newVals;
   }

   public static Object[] deleteArrayObject(Object[] vals, int idx) {
      Object[] newVals = new Object[vals.length - 1];
      if idx > )
         System.arraycopy(vals, 0, newVals, 0, idx);
      if idx < newVals.length )
         System.arraycopy(vals, idx + 1, newVals, idx, newVals.length - idx);
      return newVals;
   }

   public static long[] insertArrayLong(long[] vals, long val, int idx) {
      long[] newVals = new long[vals.length + 1];
      if idx > )
         System.arraycopy(vals, 0, newVals, 0, idx);
      newVals[idx= val;
      if idx < vals.length )
         System.arraycopy(vals, idx, newVals, idx + 1, vals.length - idx);
      return newVals;
   }

   public static long[] deleteArrayLong(long[] vals, int idx) {
      long[] newVals = new long[vals.length - 1];
      if idx > )
         System.arraycopy(vals, 0, newVals, 0, idx);
      if idx < newVals.length )
         System.arraycopy(vals, idx + 1, newVals, idx, newVals.length - idx);
      return newVals;
   }

   public static int[] insertArrayInt(int[] vals, int val, int idx) {
      int[] newVals = new int[vals.length + 1];
      if idx > )
         System.arraycopy(vals, 0, newVals, 0, idx);
      newVals[idx= val;
      if idx < vals.length )
         System.arraycopy(vals, idx, newVals, idx + 1, vals.length - idx);
      return newVals;
   }

   public static int[] deleteArrayInt(int[] vals, int idx) {
      int[] newVals = new int[vals.length - 1];
      if idx > )
         System.arraycopy(vals, 0, newVals, 0, idx);
      if idx < newVals.length )
         System.arraycopy(vals, idx + 1, newVals, idx, newVals.length - idx);
      return newVals;
   }

   public static short[] insertArrayShort(short[] vals, short val, int idx) {
      short[] newVals = new short[vals.length + 1];
      if idx > )
         System.arraycopy(vals, 0, newVals, 0, idx);
      newVals[idx= val;
      if idx < vals.length )
         System.arraycopy(vals, idx, newVals, idx + 1, vals.length - idx);
      return newVals;
   }

   public static short[] deleteArrayShort(short[] vals, int idx) {
      short[] newVals = new short[vals.length - 1];
      if idx > )
         System.arraycopy(vals, 0, newVals, 0, idx);
      if idx < newVals.length )
         System.arraycopy(vals, idx + 1, newVals, idx, newVals.length - idx);
      return newVals;
   }
}

   
    
    
  
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.(double type value)
16. Copies the given array and adds the given element at the end of the new array.(int value type)
17. Copies the given array and adds the given element at the end of the new array.(short type array)
18. Inserts the specified element at the specified position in the array.
19. Inserts the specified element at the specified position in the boolean-type-value array.
20. Inserts the specified element at the specified position in the byte-type-value array.
21. Inserts the specified element at the specified position in the char-type-value array.
22. Inserts the specified element at the specified position in the double-type-value array.
23. Inserts the specified element at the specified position in the float-value-type array.
24. Inserts the specified element at the specified position in the int-type-value array.
25. Inserts the specified element at the specified position in the long-type-value array.
26. Inserts the specified element at the specified position in the short-value-type array.
27. Removes the element at the specified position from the specified array.
28. Removes the element at the specified position from the specified long type array.
29. Removes the first occurrence of the specified element from the specified array.
30. Removes the first occurrence of the specified element from the specified long value 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.