ArrayList 1 « ArrayList « Java Collection Q&A

Home
Java Collection Q&A
1.algorithm
2.array
3.Array Byte
4.Array Char
5.Array Convert
6.Array Dimension
7.Array Integer
8.Array Object
9.Array String
10.ArrayList
11.collection
12.comparator
13.Development
14.Garbage Collection
15.Generic
16.hash
17.HashMap
18.HashTable
19.iterator
20.LinkedList
21.List
22.Map
23.queue
24.Set
25.Sort
26.tree
Java Collection Q&A » ArrayList » ArrayList 1 

1. How to backup ArrayList in Java?    stackoverflow.com

I have some data stored as ArrayList. And when I want to backup this data,java bounds two objects forever. Which means when I change values in data ArrayList this changes come ...

2. Usefulness of ArrayList.clear()?    stackoverflow.com

I was looking through the Java documentation, and I came across the clear() method of ArrayLists. What's the use of this, as opposed to simply reassigning a new ArrayList object to ...

3. Initialization of an ArrayList in one line    stackoverflow.com

I am willing to create a list of options to test something. I was doing:

ArrayList<String> places = new ArrayList<String>();
places.add("Buenos Aires");
places.add("Córdoba");
places.add("La Plata");
I refactor the code doing:
ArrayList<String> places = new ArrayList<String>(
    ...

4. Java errors and syntax. Any help appreciated    stackoverflow.com

I am asking for help on self-help, which is kind of an oxymoron. How do I bug you nice folks less by solving more of my own problems? I am in ...

5. How can I slice an ArrayList out of an ArrayList in Java?    stackoverflow.com

How do I get an array slice of an ArrayList in Java? Specifically I want to do something like this:

ArrayList<Integer> inputA = input.subList(0, input.size()/2);
// where 'input' is a prepouplated ArrayList<Integer>
So ...

6. 2d ArrayList in Java adding data    stackoverflow.com

I need little help on a homework assignment. I have to create a 10 by 10 ArrayList, not an array that would make too much sense. This is what I have ...

7. please help with arraylists problem    stackoverflow.com

i'm trying to get my program to compile but its giving me 5 errors

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;
import java.lang.*;
import java.text.*;
import java.net.*;
import java.util.Scanner;

public class AddressBook extends JFrame implements ActionListener
{

FlowLayout leftLayout;

  ...

8. moving through Java ArrayList with a undo button    stackoverflow.com

I know that I am missing something simple here. I have got this homework all done except for moving through my ArrayList. This is a undo feature of a calculator ...

9. For-Each and Pointers in Java    stackoverflow.com

Ok, so I'm tyring to iterate through an ArrayList and remove a specefic element. However, I am having some trouble using the For-Each like structure. When I run the following code:

ArrayList<String> ...

10. java issues with arraylist    stackoverflow.com

I'm a bit new to java, so please bear with me. I have a class that contains 2 arraylists which i'm trying to store objects into, one for each object type. ...

11. Growth Policy of ArrayList in Java 6SE    stackoverflow.com

I was wondering if anyone knows the growth policy of ArrayList in Java 1.6? The java doc says

The details of the growth policy are not specified beyond the ...

12. Different implementations of ArrayList    stackoverflow.com

We're getting this error

java.lang.NullPointerException
    at java.util.ArrayList.<init>(Unknown Source)
    at de.mystuff.ExtendedArrayList.<init>(ExtendedArrayList.java:38)
where ExtendedArrayList:38 is
new ArrayList(new ArrayCollection<E>(data));
In short: the ArrayList constructor sometimes seems to choke on our home grown ...

13. ArrayList Confusion and assistance!    stackoverflow.com

basically id like a few hints or tips on how to solve this question.. maybe a few things which i could read up on about arraylists and loop which would make ...

14. Time complexity for java ArrayList    stackoverflow.com

Is ArrayList an array or a list in java? what is the time complexity for the get operation, is it O(n) or O(1)?

15. Java: Adding to an array list    stackoverflow.com

public class Maze
{
    public static final int ACTIVE = 0;
    public static final int EXPLORER_WIN = 1;
    public static final int MONSTER_WIN ...

16. Optimize this ArrayList join method    stackoverflow.com

I have written this code to join ArrayList elements: Can it be optimized more? Or is there a better different way doing this?

public static String join(ArrayList list, char delim) {
   ...

17. Passing parametrized ArrayList to a function in java    stackoverflow.com

I have the following fucntion.

func(ArrayList `<String>`[] name) { ........ }  
The function fills the ArrayList[]. (I don't want to return the ArrayList[]) However, in the caller function the ...

18. Java: ArrayList bottleneck    stackoverflow.com

while profiling a java application that calculates hierarchical clustering of thousands of elements I realized that ArrayList.get occupies like half of the CPU needed in the clusterization part of the execution. The ...

19. Dealing with ArrayLists in java...all members of the arraylist updating themselves?    stackoverflow.com

I have a function that shrinks the size of a "Food bank" (represented by a rectangle in my GUI) once some of the food has been taken. I have ...

20. How to avoid null pointer error    stackoverflow.com

I trying to find whether the elements of 2 arrayLists are match or not. But this code give me error Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException since some of the elements are null. ...

21. Java: substitute for ArrayList cos primitive types not allowed in ArrayList?    stackoverflow.com

Primitive types are not allowed in ArrayList, source. Partial solution: you can wrap prim.types such as int to Integer to form an extra class but a side effect. I ...

22. Adding instances of a class to an Arraylist in java    stackoverflow.com

I have 10 instances of the class movie which I wish to add to an Arraylist named Catalogue1 in a class containing a main method I write the following

 ArrayList catalogue1= ...

23. Is there a Java data structure that is effectively an ArrayList with double indicies and built-in interpolation?    stackoverflow.com

I am looking for a pre-built Java data structure with the following characteristics:

  1. It should look something like an ArrayList but should allow indexing via double-precision rather than integers. Note that ...

24. how to use an array list?    stackoverflow.com

I need to know if i store my data in an ArrayList and I need to get the value that I've stored in it For example : if I have an ...

25. How does Java handle ArrayList refrerences and assignments?    stackoverflow.com

I mostly write in C but am using Java for this project. I want to know what Java is doing here under the hood.

ArrayList<Integer> prevRow, currRow;
currRow = new ArrayList<Integer>();
for(i =0; ...

26. Beginner question: ArrayList can't seem to get it right! Pls help    stackoverflow.com

I have been staring at this code all day now, but just can't get it right. ATM I am just pushing codeblocks around without being able to concentrate anymore, with the ...

27. Pass reference to ArrayLists to a method    stackoverflow.com

here is the whole program:

public  class ListMerge
{
  public static void main( String[] args)
    {

       Scanner input = new Scanner(System.in);

  ...

28. java arraylist format    stackoverflow.com

I am having one problem in java arraylist. I am good in databases :) We normally use "group by" to group rows. I want the same thing but in java for one ...

29. Empty ArrayList equals null    stackoverflow.com

Is an empty Arraylist (with nulls as its items) be considered as null? So, essentially would the below statement be true:

if (arrayList != null) 
thanks

30. How do you get a float[] out of an ArrayList in Java    stackoverflow.com

I have gotten a float array stuck inside of a ArrayList. the arraylist contains a Boolean and the afore mentioned float array. my courrent code to get it out (which doesn't ...

31. Question about using ArrayList in Java?    stackoverflow.com

I really do not know if the title is appropriate or not. I have 2 options: OPTION 1:

Class A {
   ArrayList<B> BList = new ArrayList<B>();

   public B[] getBList() {
 ...

32. why does this code output "0"?    stackoverflow.com

package Algorithms;
import cs1.Keyboard;
import java.util.*;

public class SieveofEratosthenes2 {
    public static void main (String[] args){

        //input number and create an array with the ...

33. java arraylist help needed    stackoverflow.com

Have coded in many languages before but new to Java. I want to create an array whose members are of type

public class data
    {
     ...

34. ArrayList in J2ME?    stackoverflow.com

I have an arraylist of database records. I want to put it in my J2ME List. But there is no split or arraylist in J2ME. How can I do it? A ...

35. How does ArrayList work?    stackoverflow.com

What data structure does an ArrayList use internally?

36. Grabbing Random from ArrayList    stackoverflow.com

I have an ArrayList which stores 52 card objects like so:

 public class Pack

{
   private ArrayList<Card> cards;
   private Card RandomCard;


   public static void main(String[] args) ...

37. how to define an arrayList with two columns in java?    stackoverflow.com

I have a hashMap. Each "Value"is going to be a a list which will be mapped later on with my "Key"s. List is desired to look like this: [length,time][length,time][length,time] For example: Key{srcAddr=x, dstAddr=y, srcPort=12345, ...

38. LinkedHashSet or ArrayList    stackoverflow.com

I wish to

  1. Avoid duplicated item being inserted.
  2. When I iterate through the collection class, the returned item is same as insertion order.
May I know, what thing I should consider, to choose either ...

39. Initializing ArrayList with a new operator in Java?    stackoverflow.com

What is the best practice to initialize an ArrayList in Java? If I initialize a ArrayList using new operator then, the ArrayList will by default have memory allocated for the 10 buckets ...

40. Java Problems - ArrayList and Time Elapsed Function    stackoverflow.com

I'm trying to create 5 ArrayLists of various size, fill them with random numbers between 0 and 1, and then time (and print) how long it takes to iterate through each. I ...

41. Help summing a arraylist    stackoverflow.com

Currently the code below will give me a line by line listing of the values, if i wanted to sum the values for one total, can someone give me an example ...

42. How to return an arraylist from a method    stackoverflow.com


I need help. For this specific method. I am trying to get it to return an arraylist that I tokenized.
public ArrayList read (){

  BufferedReader inputStream = null;
  try {
 ...

43. Problems with my program involving arraylists, bufferedreader, methods, and overall forgetfullness of how java works    stackoverflow.com

I am having difficulties with a program that I have been working on all day. I am trying to read a text file and read each line one at a ...

44. Input for an ArrayList    stackoverflow.com

I'm having issues formatting an input String into an ArrayList. I commented out some of the things I've tried. Initially I tried to put the input into a string ...

45. Java Arraylist Help    stackoverflow.com

Alright so I'm trying to get this class work:

public boolean hasPoint(Point p){

    for (int i=0; i<this.points.size(); i++){
        // Right here
  ...

46. ArrayList or Hashset    stackoverflow.com

ArrayList queryParms = new ArrayList();
StringBuffer sql = new StringBuffer();
sql.append(
"SELECT A.FLDREC_NUM, " +
"@CHARDATE(A.FLDDATE), " +
"T.FLDDESCR, @DEC(A.FLDLEVEL,3) " +
" FROM @SCHEMAALCOHOL A LEFT OUTER JOIN @SCHEMADRUGCAUS T " +
" ON A.FLDREASON = T.FLDCODE ...

47. Using .add for arraylist doesn't seem to work, what am I doing wrong?    stackoverflow.com


 public boolean addPoint(Point p){
  points.add(p);
  return points.add(p);
        extremes();
 }

Alright so when I run this code the main class calls addPoint and ...

48. How to make an ArrayList    stackoverflow.com

I have a homework assignemnt that I have been working with for the past few days and I just keep on going circles and circles thinking that I got the codes ...

49. I have a homework assignement about arraylist    stackoverflow.com

I have a homework assignemnt that I have been working with for the past few days and I just keep on going circles and circles thinking that I got the codes ...

50. What's the C++ version of Java's ArrayList    stackoverflow.com

Just getting back into using C++ and trying to convert a simple Java program I wrote recently. What's the preferred equivalent to the Java ArrayList in C++?

51. Java ArrayList: Merging ArrayLists within ArrayLists to create one ArrayList :O    stackoverflow.com

I've looked around but I can't seem to find an API call that does the following: I need to merge all ArrayLists in an ArrayList to form one ArrayList with all ...

52. What will happen to arraylist in this code?    stackoverflow.com

ArrayList userItem = new ArrayList();

userItem.add(item.getUserId()+"|"+item.getEmail()+"|"+item.getImgInstance());

ArrayList userItem = onlineUsers.get(item.getImgInstance());
I want to know what the last line will do to the list will it append the value of onlineUsers.get(item.getImgInstance()) in the previous string ...

53. problem with ArrayList in Java    stackoverflow.com

I have issues getting my ArrayList to add properly. When I print the ArrayList after the for loop has finished, the ArrayList is the correct length, but every element is the ...

54. Java Bean ArrayList    stackoverflow.com

I have an ArrayList of Strings in my java bean. I want to be able to add/remove from this list at design time in the property editor. How do ...

55. How to randomize arraylist    stackoverflow.com

I have two arraylist filelist and imgList which related to each other, e.g. "H1.txt" related to "e1.jpg". How to automatically randomized the list of imgList according to the randomization of fileList? ...

56. ArrayList in Java - What is wrong with my single line of code?    stackoverflow.com

I've tried comparing this to examples and I just can't seem to find out why this will not compile so I was hoping for some insight.

ArrayList<Integer> listOfPrimeNumbers(initialCapacity) = new ArrayList<Integer>( );
is ...

57. differentiate between each children classes in an arraylist of parent class    stackoverflow.com

hi I have a parent class that is Abstract Employee and I have childrens Secretary, Engineer, Technician If i have ArrayList<Employee> employees; and in a for loop I have randomly made ...

58. Java - ArrayList of Modules - how do I    stackoverflow.com

list all modules in the ArraryList? - I thought it'd be something like below but this won't compile (error - cannot find symbol - method list).

/**
 * This method lists all ...

59. Apache FOP : multiple page PDF from xml array list iteration    stackoverflow.com

I have xml document that contains an array/list of complex elements. I would like to generate a PDF file such that each complex element is displayed on a new page. I ...

60. What does the {{ syntax on ArrayList initializer really do    stackoverflow.com

I have recently found what appears to me to be a new syntax for statically initializing an ArrayList:
new ArrayList() {{ add("first"); add("second"); }};
My question is, what is really ...

61. How to create multidemensional arraylist in Java?    stackoverflow.com

I'm fairly new to ArrayLists anyway but I need them for this project I'm doing so if you guys could help me I would be more than grateful!
Basically, I need to ...

62. Problem arrayList class    stackoverflow.com

I am having problems while listing an ArrayList. My code:

Iterator<String> iterator = (Iterator<String>) myList.iterator();
while (iterator.hasNext()) {//List tagListAux
        System.out.println("Test -> "+iterator.next());
   ...

63. Java Final arraylist    stackoverflow.com

My question is regarding declaring an arraylist as final. I know that once I write final ArrayList list = new ArrayList(); I can add, delete objects from this list, but I ...

64. Java ArrayList problem (involves valueOf())    stackoverflow.com

So I have this function, combinations, which adds to an arraylist all permutations of a string.

 public static void combinations(String prefix, String s, ArrayList PermAttr) {
      ...

65. Problem using if statement with ArrayList    stackoverflow.com

I am using an if statement as shown below,

if(sign.size()==0)
Here sign is of the type ArrayList<Character> I am trying to add a char to the ArrayList But its not working. Is there ...

66. Overwriting a row in a two dimensional arraylist    stackoverflow.com

I have a 2D arraylist containing 4 cols. I want to add a 5 th column to this arraylist. the fourth col is a set of values based on which the result ...

67. How to encapsulate an ArrayList in Java    stackoverflow.com

I am trying to write a getter for an ArrayList in Java such that the list returned cannot be modified (ideally at compile time). I know there must be some simple ...

68. Help with buttonWatcher adding Characters to an arrayList    stackoverflow.com

public class ButtonPanel extends JPanel
{
    private JButton[] buttons;
    private ArrayList<Character> playerSequence; 
    private static final Character firstChar = 'A';
    ...

69. multi-dimensional ArrayList    stackoverflow.com

Just a very small question... I seem to run into too much complexity here: I have to realize an index-structure like {42, someString}. I tried:

Object entry[][] = new Object[1][1];
ArrayList<Object> my_list = ...

70. ArrayList related debugging question    stackoverflow.com

Please help me explaning this. I can't seem to figure out why this produce a null pointer exception

/* Try to find customer in customer list, if not in list add to ...

71. Am I writing this method the right way?    stackoverflow.com

I've got an ArrayList called conveyorBelt, which stores orders that have been picked and placed on the conveyor belt. I've got another ArrayList called readyCollected which contains a list of orders ...

72. Java - array list to output all factors    stackoverflow.com

I've been asked to create a method that returns all of the factors as an array list. Any help would be appreciated as I've been stuck for some while now.

/**
 * ...

73. arraylist problem    stackoverflow.com

I am adding parsed value in an ArrayList. I am getting lot of parsed value in webservice. So I am getting out of memory error how to avoid that ? ...

74. Need help with ArrayList and Stack please    stackoverflow.com

I am having trouble starting out this program. I am supposed to write a program that will populate an ArrayList by asking the user for 10 numbers. After the list is made ...

75. Java ArrayList Help    stackoverflow.com

import java.util.ArrayList;
public class WTFAMIDOINGWRONG 
{
    public static void main(String[] args)
    {
        ArrayList<Integer> intsAR = new ArrayList<Integer>(5);
   ...

76. Unchecked warnings for Arraylist    stackoverflow.com

Why am I getting these 4 warnings from -Xlint and what should I do about them? I'm just starting in Java, so am likely missing something obvious.

import java.util.*;

class CompareGerbils implements Comparator ...

77. Java ArrayList as Parameter    stackoverflow.com

I am currently working on a lab and would like to know how to handle the following problem which I have spent at least two hours on: I am asked to create ...

78. set() in ArrayList    stackoverflow.com

I am new to Java, please help me. My program is

import java.util.*;
import java.lang.*;
class Test
{
    public static void main(String[] args)
    {
       ...

79. ArrayList is empty but why?    stackoverflow.com

I'm trying to add Cards to ArrayList deck, but it doesn't seem to work(most of the code is an example on oracle.com ). I'm probably doing something really stupid, but I ...

80. What changes to be done in ArrayList to make it behave like a Set    stackoverflow.com

What changes to be done in ArrayList to make it behave like a Set (means it should not accept any duplicate values).

81. Why primitive datatypes are not allowd in java.util.ArrayList?    stackoverflow.com

Possible Duplicate:
Storing primitive values in a Java collection?
ArrayList accepts only reference types as its element, not primitive datatypes. When trying to do so it produces ...

82. Using the ArrayList in Java    stackoverflow.com

I have made an ArrayList of type CartItem, basically it stores all the CartItems in one list. Now once a CartItem has already been added, instead of adding the same CartItem again, ...

83. Array List Help    stackoverflow.com

I'm trying to add an object to an array list but having a bit of difficulty. I know my problem, but not how to fix it. Basically, the problem is that ...

84. methods from one class to ArrayList in another class    stackoverflow.com

I have a Register class contains 8 sets& gets methods using:

public class Register {
  public Register(String Username) {
   JFrame myFrame = new JFrame();
  }

  public ...

85. Java Arraylist Data extraction    stackoverflow.com

How would you extract the data as follows: I want to extract from this arraylist:

[{itemname=Original, number=12}, {itemname=BBQ, number=23}, {itemname=CatchUp, number=23}]
This array:
{"Original":12,"BBQ":23,"CatchUp":23}
Thanks in advance! Here's the code used to generate the hashmap:
ArrayList<HashMap<String,String>> list ...

86. Writing to Binary in Java    stackoverflow.com

I am making a program that makes use of two Array Lists. I've researched how to write the objects to binary and I've tried implementing it but it never works correctly. ...

87. Why do people create arraylist like this?    stackoverflow.com

Occasionally I see somebody create an arraylist like this, why?

List numbers = new ArrayList(  );
Instead of:
ArrayList<something> numbers = new ArrayList<something>();

88. How would I change this method to work with an ArrayList?    stackoverflow.com

public void critReactRoomStateChange(String command, PC pc, String name) {
    Creature temp = null;
    for (int i = 0; i < getCount(); i++) {
   ...

89. Use of ArrayList in Java    stackoverflow.com

I want to add both String and integer type of value in arraylist. For example i have array list in which i want to add name of the persons and ...

90. Instantiating a new arraylist then adding to the end of it    stackoverflow.com

public ArrayList<Person> people;
Is this how you would instantiate the people variable as a new empty ArrayList of Person objects?
ArrayList<Person> people = new ArrayList<Person>();
And is this how you would add newMember to ...

91. Argument vanishes in the middle of the method?    stackoverflow.com

Whenever I run this method the print goes perfectly fine so the argument is passed and not null. Still it gives a NullPointerException when the argument is added to the children ...

92. Having problems clearing an arrayList    stackoverflow.com

I m having a 2d arraylist and inside a loop i want to parse every 1d list of the 2d list to a temporary list. Also I want at the end ...

93. Creating a new ArrayList in Java    stackoverflow.com

Assuming that I have a class named Class, And I would like to make a new ArrayList that it's values will be of type Class. My question is that: How do I do ...

94. Dictionary of ArrayLists in Java    stackoverflow.com

I'm trying to write a simple program in Java in educational purposes. Basicly you can add students and those grades and after all collect some statistics like average students grade or filtering ...

95. Adding to Arraylists    stackoverflow.com

i know how to add many things into arraylist at once, like:


String [] things = {"eggs ", "pie ", "lasers ", "hat "}; List list1 = new ArrayList(); for (String s: things) ...

96. Java arraylist question (capture?)    stackoverflow.com

In java I have an arraylist that holds the following

 List<IMyInterface>
I am returning it in a function
List<? extends IMyInterface> getList()
Now I wanna do the following ...

97. Using JRBeanCollectionDataSource to generate reports where a bean has an arraylist of another bean    stackoverflow.com

I have a bean class ReportVO which has fname,lname and an ArrayList of SubReportVO bean. I want to use the member variables of SubReportVO bean from that arraylist to fill the report ...

98. Java ArrayList question    stackoverflow.com

I have an arrayList called A, say, which is non-empty. I create another arrayList, B, and put in some elements of A.

for(someobject obj : A){
        ...

99. Bouncing shape nested in another shape (What is wrong with this code)    stackoverflow.com

I have an application that bounces Shapes around inside a JPanel. Whenever shapes hit a side they will bounce off in the other direction. I am trying to add a new ...

100. A more efficient way to code this program    stackoverflow.com

This Program WAS homework. We have already finished it and are good to go. I was wondering if there is a more streamlined way of writing this program? The program is ...

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.