ArrayList 8 « 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 8 

1. Differense between ArrayLIst Vs Vecot

2. ArrayList members to binary tree nodes

But it doesnt know what tree is. So that wont compile. Then I tried just plain "insert(I)" and Exception in thread "main" java.lang.Error: Unresolved compilation problem: The method insert(E) in the type BinarySearchTree is not applicable for the arguments (Integer) Edited by: wrlwnd on Mar 12, 2009 3:42 PM Edited by: wrlwnd on Mar 12, 2009 3:44 PM Edited by: wrlwnd ...

3. Declaring Arraylist

Declaring an arraylist as type is not gonna score you good points in future maintenance of your code. Java should be strongly typed and if you are giving classes/objects the name of Item then you are headed for trouble. Some more meaningful names like PhoneBookEntry, PrivateContractor, LibraryBook etc. are what you should be aiming at.

4. ArrayList help

5. Help with ArrayList

6. Best way to walk through an ArrayList

7. Is a "2-dimensional arrayList" practical, and problem creating one?

I'm going to stay away from the arrayList for now, as you all have stated. However, pbrockway2 logic works if I were to create a 2-dimensional array list and in that case his reply is correct, however, in my case probably not the best idea. Also, when I said ArrayList grid = new ArrayList(30), I set it to 30 for clearity ...

8. Problem with arraylists

So i have to make this project which require a lot of classes, and since this is my first time making a project that require numerous classes i am having a difficult time so what i did was that i stored one arraylist that is in a train class in which i put all of my polygons points into, then i ...

9. ArrayList help

I'm not stopping trying to figure it out I'm still doing it more for me then my grade, it's bugging **** out of me because my original code compiles and it looks right but I always get an error when I run it. I'm just saving that method in case I can't figure it out. I didn't mean this at Sinanju180, ...

10. ArrayList help....

11. Help with ArrayList

A few criticisms Adopt a consistent style. Your constructor and for loop have the opening brace on the same line. Whereas everywhere else it appears on the next line down. Also indentation is not uniform. Amount only has one m. Do not give variables/parameters/methods/classes the same name. This only leads to confusion.

12. Question about arrayList

Okay I have created an ArrayList and I have it holding in one element the Artist name, genre and album name. Now I'm creating an arrayList of the songs on the album. I have these working great. My problem is how do I attach the arrayList of songs to the same element of the ArrayList with the rest of the album ...

13. ArrayList

public static int inputMenu() { //Presents the user with a menu. Scanner scanInput= new Scanner(; System.out.println("\n\n Select what you would like to do."); System.out.println(" 1. Convert from Decimal To Binary" + "\n 2. Convert from Binary to Decimal" + "\n 3. Convert from Decimal To Octal" + "\n 4. Convert from Octal To Decimal" + "\n 5. Convert from Decimal To ...

14. ArrayLists and classes problem

Hi, first it would be kind if you used the possibility to tag code with the appropriate option of the editor. Second: what makes you think it is a reasonable idea to make vert_graph a static field that even worse is recreated with each instance of Graph being created using the instance variable len for its size? I hope that static ...

15. Not adding to the array list

16. prinitng locations in arraylist

17. Cant add to the end of the array list

Try posting a SSCCEE. Your code could be better written: 1. You are using the enhanced for loop, then you have to turn around and use indexOf to see where you are in the list. Think about that. 2. Are you sure you have to use both equalsIgnoreCase and compareIgnoreCase to get the result you need?

18. ArrayList addition...method and client

You should more clearly define what youre constructor is supposed to do because usually constructors initialize instance variables, etc What you have here makes no sense. You created a new ArrayList in your client and then u add Integers to it and pass it to the constructor which creates a new ArrayList?? Then what? Edited by: maryjanelane on Oct 31, 2008 ...

19. extracting data from an arraylist

so as far as i understnd it should look relativley sunmilar to below? (if not can you tell me where i am going wrong) public ArrayList methodName(String word) { if (arraylistvariable.contains(word)){ arraylistvariable.remove(word); //this is wrogn i think, is the remvoe method the right method to remove an item and return, or is there a better one in the api? return something; ...

20. How to solve Type safety Warning in ArrayList

I found this explanation somewhere, don't know if it's fully correct: Well, this warning only occurs when you have a cast to a generic type. The compiler cannot generate code that correctly checks a cast against a generic type, so it warns about about that. It is just an artifact of the way Java implements generics, and most often comes up ...

21. Trouble with arraylist

Showing a bunch of single lines from your code does not help much. Most of the developers that are here to help are not interested in stealing your code, nor are we going to get upset if you post a ton of it. The other newbs may take your code and use it, but honestly who cares. From the little you ...

22. Equal method and ArrayList Testing

for(Object ob : listOB1){ if(ob.equals(intOB1)) System.out.println("Hi .... Elements Is :-> " + ob); else System.out.println("Elements Is :-> " + ob); } It shows output "Elements Is:-> 100 Hi ... Elements Is:-> 200 ". My question is -- When we process 200 member using equals() method it evaluates true How ?? Because equals() methods by default check reference while "ob" and "intOB1" ...

23. To eliminate blank rows of a .csv fiel to get stored in an arraylist

I have to read a .csv file line by line,split recordsand store it in arraylist. While reading a line if the row is blank, the row must must be eliminated. Other non-blank rows' fields must be stored in arraylist. I counted the total number of rows for checking purpose and it also counts the blank rows which should not be the ...

24. ArrayList help.

Hello. I'm having a bit of trouble searching my arraylist. I have 3 classes, books, painting and music, which has genres and artists in them, which then extends the class WorksOfArt. This is in turn added to an ArrayList in a new class called ArtCollections. Now, what I need is to be able to for example, extract songs with 2 or ...

25. Dividing ArrayList dynamically

26. Sum of arrayList using recurssion

27. A TreeMap and ArrayList question

"Embedded DB" is something different than "in-memory DB" though. An embedded DB is persistent while a in-memory one is not. If you use an embedded DB, you need to synchronize it after restart with your other data sources, and it will use disk space as well. There are use case for embedded DBs and others for in-memory DBs. Hard to say ...

28. ArrayList Help

I need help in ArrayList. I have an arraylist of strings. I am looping through this list and send them to the output stream one after the other. While i am looping through the list and sending them, it is possible that another thread will be adding some elements to it. After an element is sent, it must be removed from ...

29. ArrayList

But you need to specify the number of elements while initializing an array. But in an arraylist you can add the elements dynamically. That effectively means when you add an element to the arraylist that exceeds the size of the underlying array, JVM has to create another array of bigger size and copy the old array to the new one. Is ...

30. Passing polymorphic ArrayLists to a method expecting ArrayList

Thank you both for the responses. I gave you both helpful ratings because I think you both answered the question, just in different ways. fredrikl, your solution certainly works well. I'm sure I have seen that notation in documentation and such but haven't had experience using it yet. Your solution works out perfectly for my method since all I am trying ...

31. ArrayList

32. ArrayList inside arrayList

33. Creating ArrayList dynamically

Now i need to list the what are the vehicles under two wheeler, three wheelers, Four Wheelers, If the Four Wheelers contains the Truck and car means i need to list the Car and Truck. If the Truck is clicked then i will show the what are the Trucks listed in xml. If the user clicks the Car i will show ...

34. ArrayList-- IndexOutOfBoundsException

diff(); //repaint();//calls paintComponent //} //catch (InterruptedException e) {} // } } public void open() { ok = true; try { in = new BufferedReader(new FileReader("Output.txt")); return; } catch(IOException ie){System.out.println(""+ie);} ok = false; } public float read() { if (tokn.countTokens() > 0) return(Float.parseFloat(tokn.nextToken())); try { String s = in.readLine(); if (s == null) return(-1); tokn = new StringTokenizer(s.trim(),";"); if (tokn.countTokens() > 0) ...

35. Fetching 7 recent dates from arraylist

AneesAhamed wrote: Kayaman, I know this, but the real question is How to find * the one that matches the closest to the current date * if no today's date or 3 advanced dates are available, how to add, just the 3 recent dates (- 3 days dates)? This logic is bit tough and that is what I am stuck with! ...

36. A nudge in the right direction, ArrayList and if so, more than one?

Hello everyone, this is my first post here so firstly Hi! I am working on a project to create a personal organiser, the application needs to be able to store contact details: Name Address Home Tel Mobile Tel Email And details of appointments and notes, the finished product will be linked to a gui. Now my question is what is the ...

37. Using arrayList

38. arraylist

Have you tried looking at ArrayList's javadocs to see if there's any method that might help you? Even if you can't find such a method, if you know how to iterate over a list and if you know how to count, then you have enough knowledge to do this. (But there are methods that can make it easier in ArrayList.)

39. ArrayList problem

What were you expecting it to do? You only ever create 4 instances of Point (and for that matter, only 1 of Circle and Rectangle) and then reuse them for every shape the user wants to create. Since your shapes don't copy the points you pass in, any changes you make to those points will be reflected in every shape you ...

40. Need help with using ArrayLists with class methods

for(int i = 1; i<=list.size(); i++){ list.get(i).toString(); //Exception in thread "main" java.lang.IndexOutOfBoundsException: //Why does this error message occur? //Shouldn't list.get(i) return a Shape object? } } } **********************POINT CLASS***************************** public class Point extends Shape{ private double X, Y; Point(){ X = Y = 0; }; Point(double x, double y){ X = x; Y = y; }; public String toString(){ String temp; ...

41. How to add 2 arrayList into a an ArrayList

42. ArrayList

43. Help with method that returns an ArrayList

44. Create an ArrayList

java.lang.NullPointerException at shop.Stock.( at shop.CustomerAccount.( This tells you that at line 16 of, the CA constructor () is invoking a Stock c'tor, and that at line 12 of, in that c'tor, there's an NPE. (And you can of course read further down the stack trace to see where all that's being called from if you wish.) SO... What is ...

45. ArrayList

Instead of having three separate ArrayLists, don't you think you should only have one, which contains all the Items? Each Item should hold its own price, quantity, and name, I would think. What do you mean by "doesn't work"? When you are adding or removing quantity, you are adding or removing the global variable, which you never set equal to anything. ...

46. Unknown ?ArrayList Problem

This has nothing to do with the length of your Strings. Your remove logic in the nested for loops is bad, but this is only being demonstrated in the second example. You should re-write that segment of code (the nested for loops) but re-think what should be done by thinking through the logic on paper first.

47. arrayList in Java

48. ArrayList Extraction

I have an ArrayList (ar). That ArrayList is populated with 20 values. When I go to convert it to an Array (Face[]) I get this error: Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [LXS1.Face; at XS1.XS1Render.render( at XS1.XS1Render.main( Java Result: 1 What does this mean? How can I fix it?

49. ArrayList Problem

50. ArrayList advise

Just need a little advise. Say I create an Object which has a field called Time, which is in multiple of hours. I then create an ArrayList for this Object. Whats the best way to place these Objects into the ArrayList dependant of their time? For instance, If my first Object has a time of 2 hours, I would want it ...

51. Arraylist help

Hey everyone, quick question that has had me pulling my hairout for the last hour about arraylists. I have an arraylist called cars and several methods around that, that allow cars from this arraylist to be set to people (setPerson). I need to loop through the array list and println every car that has not been set to a person. I ...

52. Problem in ArrayList

HI All, I am full new to the Java , I faced one problem .I am using the Arraylist of arraylist for boudary checking and store in a Hashmap . Below is the values. And i have passed the "Range va;ue" like i.e "2107800" and we need to find this range under which location (pune or West). Ex: Pune : [[3104199, ...

53. ArrayList

Hi, I am creating a calculator (applet) and found a problem. I need to convert the arraylist into an integer. This is because for every bottonclick (on the numbers) it stores it as an integer in the arraylist. Then i need to grab the whole list and turn it into 1 integer, so I would be able to add that integer ...

54. ARRAYLIST comarision failing.

codingMonkey wrote: Please use code tags when posting code. You can do this using the CODE button above the forum editor. Few people will bother to read unformatted code. This time I did bother to read the unformatted code, specifically to learn a new language. However I am not entirely sure what the language I learnt is called, so lets call ...

55. RangeCheck method naming convention in ArrayList

I admit I've started doing that (and the inverse in C#)... IE: Non-private methods follow the camelCase convention... all private methods in PascalCase... so I can immediately see from the name what's private, and what's not. I suppose might one regard this as sloppy; and it certainly goes against the established conventions... my collegues (those who've seen it) aren't actively apposed ...

56. ArrayList manipulation

57. Packaging, and a quick question on ArrayLists

I've solved my error, now all three classes compile perfectly Thank you for the help, BigDaddy, and thanks for the Collections tip. I looked into an article on generics and I kind of get the hang of it, and intend to look into it a little more in the future Answer solved(:

58. Data-structure to use: ArrayList, SynchronousQueue, LinkedBlockingQueue ?

Hi, I have a small application, which have 2 portions, one is producer and other is consumer pieces of code. The producer reads the data (record by record) from a file, parses and validates it. Consumer again validates it and writes it record by record into a text file. And we gonna have 2 threads, producer code will be in main ...

59. Add method of an ArrayList

/** * Inserts the specified element at the specified position in this * list. Shifts the element currently at that position (if any) and * any subsequent elements to the right (adds one to their indices). * * @param index index at which the specified element is to be inserted * @param element element to be inserted * @throws IndexOutOfBoundsException {@inheritDoc} ...

60. Add method equivalent to an arraylist

it's supposed to add the obj to the end of the SmartArray. This will involve increasing the size of the SmartArray by 1. Once you have ensured that the SmartArray has sufficient capacity for another new element [this is the method, ensureCapacity] , you can simply put the new element in the correct location in the array, and increase the size ...

61. leading zero is kept in arraylist ---

62. Question on import java.util.ArrayList, etc.

63. Arraylist problem

65. arraylist methods help please

here is some more information thanks: The car store class needs to keep a list of cars that are available and a list of people who can borrow them. Lists of variable length can be created using the ArrayList class. When a car is taken from the car pool using the takeOut method the person who has borrowed it must be ...

66. ArrayList wierdness

Hello I create an ArrayList, add some elements from within a loop. Outside the loop I attempt to add an additional element with a index of the total added within the loop+1. It give an IndexOutofBounds exception. How can this be? It is an ArrayList, I confirmed with getClass. I even tried to create a new ArrayList from it and the ...

67. Testing, cannot clear ArrayList

68. ClassCastException on arraylist?

69. ArrayList

70. Add a Shape to ArrayList

71. ArrayList between classes

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at ListPassengersView.showList( at ListPassengersView.( at BookingSystem.listPassengers_actionPerformed( at BookingSystem.access$200( at BookingSystem$3.actionPerformed( at javax.swing.AbstractButton.fireActionPerformed( 95) at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.jav a:2318) at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel .java:387) at javax.swing.DefaultButtonModel.setPressed( ) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonL at java.awt.Component.processMouseEvent( at javax.swing.JComponent.processMouseEvent( at java.awt.Component.processEvent( at java.awt.Container.processEvent( at java.awt.Component.dispatchEventImpl( at java.awt.Container.dispatchEventImpl( at java.awt.Component.dispatchEvent( at java.awt.LightweightDispatcher.retargetMouseEvent( ) at java.awt.LightweightDispatcher.processMouseEvent( at java.awt.LightweightDispatcher.dispatchEvent( at java.awt.Container.dispatchEventImpl( at java.awt.Window.dispatchEventImpl( at java.awt.Component.dispatchEvent( at java.awt.EventQueue.dispatchEvent( ...

72. ArrayList between classes

What i have done is place a setAir method in both my AddPassenger and ListPassengers view's. I am then going to create the Aircraft in my main interface and where i set the JPanel's onto its JFrame, i will invoke the setAir method. This way, all classes should be working with the same Aircraft Object.

73. Bank account array list

I'm very lost and need a push in the right direction. I am trying to get the balance of a bank account which is an array list of accounts and balances. The class I am working on is the Bank class. There is also a BankAccount class and a BankTester class. //deposit funds public void deposit(int accountNumber, double amount) { double ...

74. Manipulating ArrayList

_sucxent.reconstruct.split is an array list which contains all the elements like JunctionList junctionID J2 xJunction 267.0 ... ... Junction junctionID J9 xJunction 392.0 ... ... Junction junctionID J1 xJunction 300.0 .add() is the add method of the array list. For the full list, I want to add the JunctionList element when i detect the Junction element.

75. How to append the two arrayList in java ? How To Ask Questions The Smart Way Eric Steven Raymond Rick Moen Write in clear, grammatical, correctly-spelled language We've found by experience that people who are careless and sloppy writers are usually also careless and sloppy at thinking and coding (often enough to bet on, anyway). Answering questions for careless and sloppy thinkers is not rewarding; we'd rather spend our ...

76. ArrayList .set() method error -- need some help.

In the assignment we are suppose to be able to use a list w any subclass of Number but then we are to use that method to get the double values for all the numbers in the list. I am trying to take each number and get the double value of it and place it back into the list. Such as ...

77. Using a method from an ArrayList

Casting it fixed the problem. I tried casting before but I think I did it wrong. As for it not doing what I want, all it's supposed to do is check the arraylist, for Treasures, and return true if all treasures have their found variables set to true. It returns false if even one is not set to true.

78. Array List

79. arraylist help

i have made a games library, i have used arraylist to store all games in the library. now when a person borrows the game from the arraylist i want everyother person not to be able to borrow this item. however i dont want to remove the game from the arraylist. how would i go about doing this. thanks any help or ...

80. ArrayList

81. ArrayList Question

I have an array list which stores the different elements of a path. Now i want to insert the leaf values of the elements in between each element. However, because my leaf value is in an array, it inserts for me the whole chunk of leaf values, but i only want a leaf value to be inserted appropriately after each element. ...

82. Need a bit of help w/ ArrayLists

This is what i have so far for my player class. Also, I do not know what hash maps are because we haven't learned them yet. So, is there a way to link 2 ArrayLists, or is that something more advanced that i will have to wait for? Edited by: Supp4sk1llz on Dec 21, 2008 8:42 AM

84. ArrayList Question

Quick Question. I'm writing a High Score table, so far so good. My only problem is that I can't think of a way to match the sorted list with the unsorted list Example: USR A 200 USR B 100 USR C 150 In my code I add the integer to its own list and sort it, and the "USR" strings to ...

85. Problem In ArrayList

this my program in which each time i will pass some parameter to access database value this should be stored in ArrayList and i will access the value for creating button at runtime.. but i getting error as follows ===========> SalesRep.getSalesPerson: select * from (select name, rownum as row_num from c_bpartner where ISSALESREP ='Y' AND ad_client_id=1000005 AND ad_org_id =1000007 ) where ...

86. Creating ArrayList from existing ArrayList

87. ArrayList with in ArrayLists

88. Further problem with ArrayLists

So none of that code is actually yours, right? You were given this code and an assignment to do some more work to finish it, and now want us to do it for you. I just want to make sure I have the facts before I start preparing snacks for you to eat while you wait.

89. Creating an ArrayList as an attribute

Admin_ID Loan_ID Payment_Date Payment_Amount Payment_To_Principle 0001 0001 2000-05-10 00:00:00 1000.0000 600.0000 0001 0001 2000-06-10 00:00:00 1000.0000 610.0000 0001 0002 2000-06-15 00:00:00 1500.0000 1000.0000 0100 0001 2000-07-10 00:00:00 1000.0000 620.0000 in this program we only want the payments for loan id '0001'. So in my code you can see that I query as follows: ResultSet resultSet2 = statement.executeQuery("select * from payments where ...

90. Aliasing in 2 Dimensional Arraylists

91. ArrayList Question.

I have an arraylist called weekDays which contains an object element. I want to be able to loop through the arraylist each time and check against last element in the arraylist to see that it is not duplicated. If it is duplicated, I want it removed from the list. Can anyone help me, please.

92. Is this a bug in ArrayList or is it intended?

Hi all, During past weekend, I was participating in a programming contest, where I found a bug in Java ArrayList class. When I added a string to the ArrayList (I used ArrayList, of course), the added string's first letter was automatically capitalized. I was doing simple searching if a string (case sensitive) exists in the list and add if it doesn't ...

93. Need help with addItem in my own ArrayList type class

a) Use an ArrayList, and Collections.sort() with a comparator. b) I would start at the front of the array. Walk through until you find the insertion point. Use System.arraycopy() to push everything from that point back one. Insert your item. c) This type of problem is solvable with a piece of paper and a pencil. Write out the starting state, then ...

95. ArrayLists question

Because you are copying a reference to that object, so you now have 2 Lists which both have references to the same object in memory i.e. both elements in the List point to the same place in memory. If you wish them to be different you have to implement "clone()" in your object, and clone them all into the new List. ...

96. Saving coordinates in ArrayList

97. Better way to compare/update two arrayList

Hi I am just wondering if there is a better way to compare and update two arrays of arrayList I have two arrays. Array1 has the following data id, name, indicator 0, bob, 0 1, mary, 0 2, john, 0 Array 2 has the following data id, indicator 0, 1 1, 1 I want to compare the two arrays and update ...

98. ArrayLists

Okay, so I have these two ArrayLists - One for product name, and another for product cost. The user can run a method to enter the name of a product and then its cost. The costs of the files and the product names are written to two different text files. Now, the problem with this is, that how do I go ...

99. somebody please helppp... me with ArrayList

I'm having trouble with passing and receiving ArrayList... Here is the code which is showing the compilation error: " expected" <> ArrayList gold = new ArrayList(); // = new ArrayList(); gold=p1.get_goldAL(); public void set_goldAL(ArrayList gold) { p2.set_goldAL(gold); } i m receiving arraylist using the method from another class as follow: <> public ArrayList get_goldAL() { return brd.get_goldAL(); } which ...

100. referencing a class with a arraylist

but since a Arraylist can grow on demand how do i call/ reference a class i cant do it the same way as i have done above because (b.set(), c.set(), d.set()) have set values. i was thinking of something like this but ovisly its not going to work Bar b[] = new Bar(); b.set(10);  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.