ArrayList 7 « ArrayList « Java Collection Q&A

Java Collection Q&A
3.Array Byte
4.Array Char
5.Array Convert
6.Array Dimension
7.Array Integer
8.Array Object
9.Array String
14.Garbage Collection
Java Collection Q&A » ArrayList » ArrayList 7 

1. Problem with ArrayList

2. MetaClass and ArrayLists

/* This part of the code finds methods. It utilizes a int called stack to do this. It starts at the beginning of the line and looks first for a ". If one is found, the line is skipped. If it finds a modifier, it then looks for either a second modifier or a primitive data type. If one of those ...

3. arraylist.add() problem

The constructor is either going to return an element, or throw an exception. So data would get into the array, unless the add() method is not being invoked. It's not being invoked because an exception is being thrown, or because you're not actually invoking it at all. Another possibility: another part of your program is overwriting the customers list with a ...

4. Resetting an array list

I have an ArrayList that keeps a running total on a per game basis. When the user resets the game I want to clear that list for the next game but cannot figure out how. I tried setting the list equal to null but the next run raises a nullPointerException. Any suggestions?

5. Arraylist class methods

6. I/O and ArrayList Problem

So I am new here, I try to not use resources like this to complete my programs, but I am stumped and cannot seem to find a solution to my problem. Basically I have a program that is controlled by switch statements and it creats an Array to store data. You can add, search, etc. You can also save the array ...

7. can you have multidimensional arrayLists?

8. are multidimnsional arraylists possible

Good day to you all, I am just wondering if multidimensional arraylists are allowed in java. I have a model with different nodes connected together by labelled lines. what i want to do is be able to retrieve what worlds are connected by which lines. i know it is possible with multidimensional arrays, because both the rows and the columns can ...

9. ArrayList

10. how do i use ArrayList with multiple collumns?

Is a list of lists better than an arraylist? or am i just missing it. Does it work in the same way with going line by line interator? Do you use a list to define the arraylist? I am going to be storing large amounts of data, like 80,000 records from txt file, LoL, any problems. I havent used a list ...

12. how to use ArrayList

13. Creating arraylists during run-time.

I'm writing a client/server application and want to create arrays during run time. I know this is easily done. But what I want to do is name the lists "clientX" where X is the numerical id of the connected client. For example, 20 clients connect to the server. I want the server to create an ArrayList for each client upon connection ...

14. ArrayList problem

} while (!front.equalsIgnoreCase("0")); System.out.println("Do you want to save the deck? 1- yes"); BufferedReader br = new BufferedReader(new InputStreamReader(; try { dummy= br.readLine(); } catch (IOException ioe) { System.out.println("IO error trying to read entry!"); System.exit(1); } iopt=Integer.valueOf(dummy).intValue(); if (iopt==1) newdeck.savedeck(newdeck); return newdeck; } public int savedeck(Deck decktosave){ FileOutputStream out; // declare a file output object PrintStream p; // declare a print stream ...

15. Help With ArrayList

17. type parameter in ArrayList

18. ArrayList - JDK compatability?

Hi folks I am trying to initilize & execute a basic ArrayList, when I try to compile it's throwing following error is that because of the JDK version? %> :Class ArrayList not found in type declaration. private ArrayList Observer; Right now I am using JDK1.1.8 is there any latest version available... Thanks LORD

19. Array list

Just don't add more than 10 customers. If you want to enforce that programatically, then try extending ArrayList (I think it's final, but can't check right now) and override the add to impose your facile limitation... If that doesn't work wrap ArrayList in a DodgyArrayList... make sure it implements all the same interfaces as ArrayList. Yuk! Failing that refer to option ...

20. ArrayList problem ....

21. Array List

Hi, I am new to Java.I want a solution for my problem. Scenario for my problem is: My project is in Healthcare.I want to "add multiple dependents" thru a jsp. A dependent has various fields such as Name,Age,Address,*** etc. Plz tell me how to get these values from jsp to servlet so that I can update the database for the given ...

22. ArrayList help

24. ArrayLists

Where are the null errors coming from? the buildings? the rooms? Are you initializing your Room objects before putting them in the arraylist? If not, then there is your problem. Consider initializing the object in the buildings.add method by creating an anonymous object. If you did that, you would have to add an instance field to Room for the roomName, but ...

25. ArrayList manipulation and Comparators

The Person class does not have a meaningful toString() method. You should override the toString() method to provide meaningful data associated with the object. To have data in a certain order requires you to sort it in some manner or another. I'm off to another boring meeting but I'm sure one of my esteemed colleagues will continue for me. Good luck ...

26. Making buttons for an ArrayList

I am in a hurry as this program has to be handed in tomorrow so quick replys would be helpful. I dont know how to make buttons in my GUI for an ArrayList and have it respond individualy with the name of the button i.e. i want to make it so that when you click on the drill button it will ...

27. working with arraylist for first time, not adding up!

/** The Hotel will have an addRoom method that will create each room with the required information: room number, bed type, smoking/non-smoking, and the room rate. Create at least 5 rooms with different characteristics. Each room will also have a boolean field called occupied attribute that will be set to false when the room is created.**/

28. Using a MergeSort with an Array List

29. Problem with ArrayList method

30. ArrayList other classes

} /** * An example of a method - replace this comment with your own * * @param y a sample parameter for a method * @return the sum of x and y */ public String searchByAuthor(String author) { for(String book : books) { if(book.getAuthor().equals(author)) { return book; } } return null; } public void enterBook(String book) { //books.add(newbook); books.add(book); // ...

31. ArrayList inside ArrayList

32. Simple arraylist problem

Well if you want to add a student to the arraylist then you need to create a new student object, and then fill in the parameters which will take some considerable time, esp if you have over 100 students... creating the students within the populate method should save a lot of time... in theory. He states that we only need to ...

33. arraylist in abstract class?

i just want to ask a simple it possible to create an arraylist in an abstract class? because there is no constructor in an abstract class and i normally create an arraylist in constructor. say if it is possible, will i be able to add or remove an element from the arraylist when i add these methods in a normal ...

34. ArrayList question

All that an ArrayList holds is a bunch of references to objects not the object itself. So what you are doing is creating a Vehicle object and setting some values ie Honda. Then a reference to that object is added to the List. You then change the make of that SAME object to Acura and add the SAME reference to the ...

35. ArrayList

hey i have a class which stores information about a person i would like to have an add method in an array list in another class this is the idea i have about how to implement this which i found in a tutorial ArrayList people = new ArrayList(); people.add(new person (???)); i would appreciate it if anyone could tell me if ...

36. ArrayList

37. I need ungrowable ArrayList

38. question about hashSets and Arraylist

i was learning collection in java. i know about arraylist but never knew about HashSet so i started programming just a basic program adding deleting, sorting and searching. but i dont find any difference in the output whether i do with Arraylist or use HashSet its The same identicial. am i right?

39. Error with ArrayList - I think.

Bear in mind that you can turn any collection into a regular array of Object with the toArray() method This is extremely useful for iterating over all members of the array with the side-effect that the original collection can safely be modified (for example by another thread) while you're iterating. For small collections it is also fairly efficient.

40. adding to arrayList

In your for loop you are trying to add an object to the list you are looping through. You cannot do this, you should set some boolean variable if the book is found in the list, then after the for loop add your book if it was not found. And you'd probably be better off using .equals() instead of .contains() to ...

41. Why wont this add to my ArrayList???

42. can not add a member to arraylist

System.out.println("Sorry, the ID already exists in the libaray"); } else { members.add(newMember); The issue is that im not able to add the new member to the arraylist if the new member's ID is not the same as the other Member IDs in the arraylist. When i check the size of the arraylist with size.(), it just returns the value 0. Not ...

43. Another issue with arraylist, kinda weird

Thanks Bernie, you made that code work. However, I got another issue. That looks like arraylist.add(), replaces all entries rather than adds to the end of the list. I cannot find what is wrong with that. But you or some other expert will probably notice what is wrong. the code, that is below, prints : 4 4 4 4 4 import ...

44. array list

Remember when I asked you if you had any particular rationals in mind? I assume you are talking about the set of rational numbers Q (any number that can be represented by p/q, p & q integers and q != 0). There is no "rational" type or primitive in standard java. You can make that ArrayList be any type you want, ...

45. need help plzz in arrayList + circle class

this.c = c; this.r = r; } public Point getC() { return c; } public void setC(Point c) { this.c = c; } public double getR() { return r; } public void setR(double r) { this.r = r; } public String toString(){ return "c="+ c.toString()+"r="+r; } ///////////////////////// public boolean isInside(Point testPoint ){

46. playlist with arraylist

47. arraylist problem.

48. help on ArrayLists

Hi, im pretty new to Java, and am having trouble with extending my use of ArrayLists. I have a piece of code to create an Array List, and I add objects to it in my main method using .add( ). Instead of having code creating and manipulating an ArrayList in my main method, I want to create a class called PersonList ...

49. array list help

50. ArrayList problems

I'm new to Java, and I'm having trouble with ArrayLists. I'm working through the exercised in a book called "Objects First with Java". I have an array of type 'Lots' called 'lots'. I want to run go through the array, and add any unsold lots to a new array, then return that array. In another method, I want to loop over ...

51. ArrayList

52. ArrayList Problem

Hi I am now having two arrayList for my picture uploading software. 1 ArrayList is actually to maintain the File array. So that I can actaully add or remove files frm arrayList 2nd ArrayList is for the JLabel which display the thumbnail of the images which user can select to clear or upload the files. And I map these two arrayList ...

53. ArrayList

I have created 3 arrayLists, which have data read into them from a txt file. I now want to search them, using I presume an Iterator. The search would be for example, get the make of a car with the following registration no. I have been battling with working this out, but to no avail. SO far I have got... /**getMake ...

54. Two arraylists

I didn't look really closely at your union logic - but it makes me uneasy. You could use a Set and add everything in both A and B to it. Then you can return new ArrayList(set). Also, I wouldn't use '==' the way you are. Autoboxing will probably save you - but I'd suggest using .equals() instead, to make it clear ...

55. Help with ArrayLists

56. ArrayList to hold obects

I am using an ArrayList to hold 5 distinct objects. These 5 objects are instances of 5 different classes inherited from a common parent.. The parent class has a method called foo(), which all the 5 sub-classes over-ride. After adding the 5 objects to an arraylist, I am trying to call the method foo() using for (int i=0;i <5;i++) {; ...

57. Occurencs in ArrayList

58. Unable to execute ArrayList member's method

59. ArrayList in Java on UNIX Platform

60. Help please!! Arraylist Search/Count

All of the action takes place in the DateCount class. Take a look at the countDates() method in detail. It is passed an array of String(s) where each element is a 'date', I used this just for testing and I am sure that once you get the idea, you can modify it so that the technique works for you. Anyway, all ...

61. Getting an ArrayList

62. Using arrayList.set

63. adding tokens into a arraylist

Hi friends,i tried this ,but iam facing NULL POINTER EXCEPTION.Iam new to java pls help me and also i need to keep all these tokens into a arraylist. try { f = new File("C: Documents and Settings\\sumave\\Desktop textfile.txt"); fis = new FileInputStream(f); BufferedReader d = new BufferedReader(new InputStreamReader(fis)); while(!(s = d.readLine()).equals("")) { StringTokenizer st = new StringTokenizer(s, " "); while(st.hasMoreTokens()) { ...

64. How to create model from arrayList of beans.

65. ArrayList Problem

66. Passing/returning ArrayLists

67. ArrayList problem

Those are both great answers, thanks all. I think I am going to go the Map route, it does seem to be made specifically for this kind of thing. I have taken the first 2 Java courses from Sun, but they don't mention the Map object in the coursework. Thanks for the help, all!

68. ArrayList retrieval

I have an object (a) of an (Account) class. This object (a) contains two Strings and two ints. I have no problem storing this object (a) in the ArrayList, which I have called (accounts). However, I don't understand how to simply output the contents of my object (a) from the accounts ArrayList. By that, I mean I flat out don't understand ...

69. ArrayList

70. working with ArrayList and classes

init: deps-jar: Compiling 1 source file to C:\Java\StudentRegistration\build\classes C:\Java\StudentRegistration\src\ cannot find symbol symbol : method compareto(java.lang.String) location: class java.lang.String if (s.getId().compareto(id)) C:\Java\StudentRegistration\src\ non-static variable this cannot be referenced from a static context Admissions adm = new Admissions(); C:\Java\StudentRegistration\src\ non-static variable this cannot be referenced from a static context Admissions drop = new Admissions(); C:\Java\StudentRegistration\src\ non-static variable this cannot be referenced from ...

72. ArrayList

73. multidimensional arrayList

<%=days%><%=empId%> <% pointer ++; } else { %> <%=days%> <% } }//close compareTo } //close for i=0 <% showCal.add(Calendar.DAY_OF_MONTH, 1); %> } When I was only showing 1 person's data, the ptoDays.getPtoDate().compareTo worked, but now that info is inside another arrayList, and that call doesn't work. I need something like empPriorPto.ptoDays.getPtoDate().compareTo, but can't find anything.. I know I need ...

74. manipilate arraylist in javascript

Hi Every one, On the time of form loading i'm getting one arraylist from that i have itreate the bean values in jsp page using scriptlate tag (it is table format), If the user select delete record then the particular recrd will be delete from the table and also from the arraylist. It is possible can any one suggest me how ...

75. Is it a better practice to create an ArrayList at class level?

Bad suggestion. Variables should be declared in the scope in which they are used. Also bad reasoning. It needn't bother the programmer that garbage collection isn't guaranteed to run whenever a variable goes out of scope. It's sufficient that it is guaranteed to run before the program throws a OutOfMemoryError. That said, parts of the JDK instantiate an object as a ...

76. arraycopy() VS ArrayList

77. ArrayList going out of scope?

Hi, I have a JSP running on a portal that doesn't give me much in the way of debugging information, however I believe that I have a scope problem with the following code, where I declare and initialise an ArrayList outside a for loop, but once used in the for loop, it seems to go out of scope and cannot be ...

78. Need advice for game, using ArrayList?

Hello to the Oracle forums. Was hoping I could ask for some help. I'm currently carrying out an assignment for a university class. We've been working on java-based 2D and 3D games, and the final assignment is to make a 2D game and a basic 3D rendition of the 2D game. We've been given a modified GameCore from the Developing Games ...

79. Arraylist

Have you ever read an explanation of scope, life time, and visibility? You have to declare the variables that you want to use in a scope that will be visible during execution and will result in the variable having the appropriate life time you desire: In your case you need that variable declared outside your class, in a common scope. Declare ...

81. arraylist

Regardless if index is 1 or 100000, you're trying to add something to an array list at a spot that doesn't exist. Go to the ArrayList API and see why the error is being thrown. If you really want to store TruckDrivers in a collection based on their ID, consider using a HashMap (as I already stated in my other post ...

82. About the java.util.ArrayList

83. ArrayList get

Hi, I hope some one can help me, I've been through the first 20 answers on google but cant understand where I'm going wrong. I have an arrayList called deck, which contains Card's which have enum values of cardValue and cardType. I am trying to print the top card. System.out.println((Card)deck.get(0)); It keeps just printing the object ref. Thanks,

84. paintComponent and ArrayList

85. ArrayList help- My java assignment

But when your assignment is due has nothing to do with the problem. Does it? I and many others do not care when your assignment is due. It does not guarantee you an answer any sooner than anyone else. In fact some refuse to help so it actually hinders your chances of getting help. In future only include information that is ...

86. Help with array list

Do you mean it prints out the highscore list, but only with the Player on it that played last? If so, chances are that you reinitiate it somewhere in your code. Search for uses of "scores", maybe its that easy. Edit: I believe the process is something like this: - set scores = new ArrayList - start Game - player ends ...

87. arrayList

If a new object has to be created every time a player starts playing, whether that is the first time since the program has been run or the fifth time, how can a new object be created automatically and be given a name? I wouldn't know how many games will be played.

88. equals for ArrayList.lastIndexOf()

I have a class tile public class tile implements Cloneable { int value; // 1-13 and 0 for joker int color; // 0-3 for Red Yellow Blue Black int location; // 0 for Rack, N for group on board int newGroup; ... I have an ArrayList of tiles but the lastIndexOf method is returning -1. In tile I added public boolean ...

89. Help with arrayList

Implode wrote: what if an object has multiple data types? This is a bad idea. It makes no sense to have a list containing a Spoon, a Clock, a Chair, a Caterpillar etc. On the other hand if you have Sedan, StationWagon, SUV etc classes then you should have a parent class they all extend, Car. Then you can make your ...

90. please help creating a group of my class - should I use ArrayList?

****. This seemed like the most intuitive technique to do what I wanted to do. My ultimate need is this: I need to create a bunch of myClass objects (WUDependent's) that eventually I want to loop through using a for-loop that would let me perform a function on each one. Can you suggest a better technique? Thanks! Edited by: lkb3 on ...

91. please clarify about Arraylist

[>>headdesk<<|] Why are you checking whether or not the ArrayList itself is a String of a single character (which is something entirely different from an empty string, of course, but that is beside the point). It is, of course, not the same. It is not even a String, it is an ArrayList.

92. ArrayList's with custom types

Ok so lets say i have a bank class and an account class. Inside the bank class I have an ArrayList accs. Now they account class has many of its own methods and stores a lot of data... Lets say the most essential part is the AccountNumber long. Well if i run accs.remove(account) it can never removes the account from the ...

93. help with Arraylist

94. computeAverage(ArrayList a)

95. arraylist with class methods, really confused

97. Arraylist add

98. Adding user input to an ArrayList

Basically, I have to write a program where: -I prompt the user for the names of all the courses he/she completed last year. -I prompt the user for the grades acheived in all the courses. -Then show the user all the subjects which he/she scored >93% (high achievement award marks) and <70% (needs improvement) I started off, but then got stuck ...

99. ArrayList and imports

Again, exactly what problem are you having? All you've really said is "it doesn't work," which contains no information. Don't bother posting the JDBC stuff here, as that's no relevant if your problem relates to processing a text file. Show the code that you tried and describe clearly, precisely, and thoroughly what exact problem you're having with it.

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