Swap elements of Java ArrayList : ArrayList « 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 » ArrayListScreenshots 
Swap elements of Java ArrayList
   

import java.util.ArrayList;
import java.util.Collections;

public class Main {
  public static void main(String[] args) {
    ArrayList<String> arrayList = new ArrayList<String>();

    arrayList.add("A");
    arrayList.add("B");
    arrayList.add("C");
    arrayList.add("D");
    arrayList.add("E");

    System.out.println(arrayList);
    Collections.swap(arrayList, 04);
    System.out.println(arrayList);
  }
}
/*
[A, B, C, D, E]
[E, B, C, D, A]
*/

   
    
    
  
Related examples in the same category
1. Get the size of an arraylist after and before add and remove methods
2. Use the Iterator returned from ArrayList to loop through an array list
3. Get generic Iterator from generic ArrayList
4. Convert an ArrayList into an array.
5. Pre-generics example that uses a collection.
6. shows the modern, generic form of collection classes
7. Use set method to change the value in an array list
8. Store user-defined objects in arraylist
9. pass the actual object you want removed.
10. Convert a List (ArrayList) to an Array with zero length array
11. Convert a List (ArrayList) to an Array with full length array
12. Remove duplicate items from an ArrayList
13. Looping through a Collection object: while loop, iterator, and for each
14. Append all elements of other Collection to Java ArrayList
15. Copy all elements of Java ArrayList to an Object Array
16. Get Size of Java ArrayList and loop through elements
17. Add an element to specified index of Java ArrayList
18. Get Sub List of Java ArrayList
19. Insert all elements of other Collection to Specified Index of Java ArrayList
20. Iterate through elements Java ArrayList using Iterator
21. Iterate through elements Java ArrayList using ListIterator
22. Remove all elements from Java ArrayList
23. Remove an element from specified index of Java ArrayList
24. Search an element of Java ArrayList
25. Get element in an ArrayList by index
26. Replace an element at specified index of Java ArrayList
27. Sort elements of Java ArrayList
28. Copy Elements of ArrayList to Java Vector
29. Copy Elements of One Java ArrayList to Another Java ArrayList
30. Find maximum element of Java ArrayList
31. Find Minimum element of Java ArrayList
32. Get Enumeration over Java ArrayList
33. Get Synchronized List from Java ArrayList
34. Perform Binary Search on Java ArrayList
35. Replace All Elements Of Java ArrayList
36. Replace all occurrences of specified element of Java ArrayList
37. Reverse order of all elements of Java ArrayList
38. Shuffle elements of Java ArrayList
39. Iterate through a Collection using Java Iterator
40. Sort Java ArrayList in descending order using comparator
41. Remove an element from Collection using Java Iterator
42. Replace an element from ArrayList using Java ListIterator
43. How to Convert an ArrayList into an array
44. Sort items of an ArrayList
45. Rotate elements of a collection
46. Search collection element
47. If an ArrayList contains a given item
48. Convert Collection to ArrayList?
49. A boolean is being stored and then retrieved from an ArrayList
50. Traverse through ArrayList in reverse direction using Java ListIterator
51. Traverse through ArrayList in forward direction using Java ListIterator
52. Remove an element from ArrayList using Java ListIterator
53. Get Previous and next index using Java ListIterator
54. A Map implemented with ArrayLists
55. A variant of java.util.ArrayList in which all mutative operations (add, set, and so on) are implemented by making a fresh copy of the underlying array
56. Copy On Write ArrayList
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.