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

1. Arraylist

Hello all Im trying to write a program where I increase only one field in an arraylist. My arraylist looks something like: cars.add(new Cars("Honda",20000, 13400.25,)); cars.add(new Cars ("Nissan",10000,18000.45,)); cars.add(new Cars ("BMZ", 25000, 6100.00)); cars.add(new Cars ("Ford", 18000, 28000.28,)); cars.add(new Cars ("GM",1700,10000.25,)); So Im using a find method so the user can search by type(IE Honda) then java asks to add mileage. ...

2. ArrayList

ArrayList ints = new ArrayList(); Where all int[] holds exactly one element, this should have about the same speed, maybe (I don't know) slightly faster for reading the values. But the real plus it that it consumes haft the amount of memory making it preferable if you are dealing with loads (a huge amount) of data. (Arrays handled as objects, and ...

3. Problem in ArrayList class(java.util.*)

The place where "boxing" fails is if you add an int , you can't remove it the same way: anArrayList.add(234); // this will be boxed into an Integer. anArrayList.remove(234); // this will not be boxed, it will look for element 234 So boxing is tricky and requires the programmer to know when it is happening and when not.

4. Require help with ArrayList

Hi I've started learning Java OOP a couple of weeks back and I've hit a huge wall which I'll explain in detail. I've been asked to make a small market program which can do things like modify prices, add products, remove products, etc. I've finished all my classes and so forth and I'm now at the point where a user would ...

5. Need help with get/set & arrayList in multiple methods

1:Write a class which represents one playing card. It should have a constructor to create a card from a suit and a rank. You should provide appropriate get/set methods. a method String toString() to return the name of the card, e.g. "King Diamond" 2: Write a class which represents a pack of 52 playing cards. Every card in the ...

6. Stuck with a little aspect of the array list

so the scenario is an array list with elements that has been populated using the .add() method, containing 3 variables ID fname and sname. I can run a search using an if statement with condition of having one of the variables equal to the search criteria, which prints me back the search results correctly I can refine to one search result ...

7. trouble with ArrayList

8. Problems with an ArrayList declaration.

9. ArrayList add method

import java.util.ArrayList; public class ValueStore { private ArrayList intList = new ArrayList(); private ArrayList dblList = new ArrayList(); private ArrayList boolList = new ArrayList(); private ArrayList stringList = new ArrayList(); public void add(int i) { } public void add(double d) { } public void add(boolean b) { } public void add(String s) { } }

10. ArrayList questions

I have a few questions if you guys don't mind. 1) How do you store a .txt file that you would enter on the cmd line into an arraylist? (for example on the cmd line "java hello hey.txt") 2) How do you sort words into its alphabetical letter form? (ie: hello = ehllo, pops = opps, etc.) Thanks.

11. ArrayList, incrementing and decrementing fields

I am trying to figure out how to change values stored in an arraylist. I have managed to get the values out, but the problem I am having now is I use the for each loop to go through the list and find certain values. I have that figured out, however I cannnot seem to change specific values in the list. ...

12. Phone book arrayList problem

package PhoneBookProgram; import java.util.ArrayList; import javax.swing.JOptionPane; public class PhoneBook { public static void main(String[] args) { ArrayList entries=new ArrayList(); entries.add( new PhoneBook("Robert","555-555-555"); entries.add( new PhoneBook("Jim","478-124-7235")); entries.add( new Phonebook("Greg", "478-454-7605") ); entries.add( new Phonebook("Greg", "478-454-7605") ); entries.add( new Phonebook("Greg", "478-454-7605") ); for (int x = 0; x < entries.size(); x++){ } } }

13. Noob ArrayList Question

A simple way to find out: create an ArrayList, check its size, remove an element and recheck its size. Yeah, I know just giving the answer would be quicker, but it's more important that you learn the technique of using the Java compiler to help you learn Java than that we just give you the answer.

14. JAVA is kickin my butt - Arraylist issue

Hi ya all. I've been attending programming courses for a few months, but these Arraylists are kicking my butt... i have numerous problems and i don't know where to start... 1st, i have a driver, a superclass, and 2 subclasses. (i totally hate this type of programming. gimme one program to do it all and i'd be happy.) 2nd, i have ...

15. help with ArrayLists !

here's the code i have so far for my assignement. So far as I can tell, only the findShortest and findLongest methods don't work -- but I have no idea how to get them to work! Can anyone please help? Java Code: import java.util.Scanner; import java.util.*; import java.util.Iterator; public class arrayListPractice { public static void main(String[] args){ ArrayList names = new ...

16. Getting a second, third, fourth arraylist from a class

Guys, I have tried everyting I can think of on this one and need some help. Perhaps what I am trying to do is not possible but before I spend anymore time seeing: Exception in thread "main" java.lang.StackOverflowError at Quiz.ReadCSVFile.ColA1( I thought I would ask a question. I have a class which reads a .csv file into an arraylist then shuffles ...

17. ArrayList problem

18. Arraylist to chararray

Hello, I have tried multiple ways to do this but I cannot figure it out. I have a arraylist with each 'item' in the arraylist being a seperate string. What I want to do is to turn that arraylist into a 2-dimensional char array. For example, the arraylist has these two strings in it: qwerty asdfgh I want char[0][0] to be ...

19. Array List

Hello!Sorry to bother you again! I'm trying to make an Array list and I want the user to have the ability to modify the elements.When I'm compiling this programm,the compiler can't identify the "box" ( 7 line source code).What I'm doing wrong? Thanks very much! Here is the source code: import java.util.*; public class TicketPool { public static void TicketPool(){ ArrayList ...

20. Need help with ArrayList please...

21. how to compress of arraylist

22. ArrayList Problem

//Now i didn't know what was the problem even i have a file You get a "cannot resolve symbol" message because the compiler doesn't recognize something you've typed. It's as if you instructed your friend to "fernt PL^%", to which s/he would likely reply, "Huh?". The compiler errors will tell exactly which symbols it does not recognize; correct these errors ...

23. How to get keep one column as a key and the other columns as a array list

class SearchHash { public static void main (String args[]) { int i=0; int j=0; Object newKey = new Object(); Object newValue = new Object(); Map map1 = new HashMap(); ArrayList a1 = new ArrayList(); String val; try { BufferedReader br1 = new BufferedReader ( new FileReader ( new File ("progress.txt"))); String s=""; s = br1.readLine(); while (s!=null) { StringTokenizer st = ...

24. ArrayList set

Yes you are totally losing it The problem with that version of the code is that your setThing method returns nothing, ie it has a void return type. Which means you will be attempting to pass "void" to the set method. Not going to happen! Before we go any further, please clarify. Are you attempting to insert a new Thing object ...

25. Passing ArrayList

26. Adding to ArrayList

27. retrieving from arraylist

28. Need ArrayList help.

29. Using ArrayList

public static void main(String[] args) { ArrayListTest test = new ArrayListTest(); test.fillList(); Random random = new Random(); for(int count = 0; count < 10; count++) { int index = random.nextInt(100); System.out.println("Credit at index " + index + " is " + test.getCredit(index)); } } private ArrayList list; } If you dont specify the capacity when creating an ArrayList the default capacity ...

30. ArrayList

If that's the contents of a method, then yes it would create an ArrayList, put something in it and return the ArrayList to whoever called the method. Whether or not that is "correct" depends on what you are actually trying to do. Nothing prevents you from trying it out to see if you get the expected result...

31. ArrayList confusion

32. ArrayList problem

33. how to use ArrayList?

Hi, Since I'm also a beginner, I can advise you to learn the correct types and the names for things. Like: what is an object, instance etc..This makes asking questions a lot easier. In my experience: I know these names, but I have had some problems with the answers because people assumed I didn't know what an object was. I did ...

34. How to create multiply arrayList?

35. ArrayLists

36. ArrayLists

Hi, I am fairly new to java and am working on creating a war game using ArrayLists. The problem that I am having is that after I shuffle my cards, I want to deal them alternately to 2 different players (ArrayLists). What I am not sure how to do is to move through the original arraylist one item at a time ...

37. saving an arraylist using FileWriter

hi just wondering if it is require to have a for or foreach loop to be able to saving the objects in an arraylist to a file using FileWriter in java i have a small exampleimport java.util.*; import*; public class output{ public static void main(String[] args)throws IOException{ ArrayList list = new ArrayList(); Person pers = new Person(); FileWriter output = ...

38. Compiler error - ArrayList

39. help mergesorting an arraylist

40. arraylist.get producing erros

41. Using .get on reference ArrayList

43. ArrayList

Hi, I am now learning ArrayList. I wrote some program using netbeans3.6. Code: import java.util.*; public class ArrayListemo1 { public static void main(String args[]){ ArrayList al = new ArrayList(); ...................... ....................... } } While typing the statement ArrayList al = new ArrayList(); it gives error " '(' or '[' expected. Can not ressolve the symbol ArrayList". When i run the same ...

44. doubt with ArrayList.clear() method

i have created 3 arraylists as follows.i.e; a1,a2,a3. i am adding some objects to ArrayList a1 and assigning this value to a2 and a3. my question is, if i clear ArrayList a1 the same result affecting to a2 and a3 also. why it's happening like this. Let me know the proper reason for this. import java.util.ArrayList; public class Sample { public ...

45. Getting Data from an ArrayList?

Hi i am very new to java and have very little programming experience before but as part of by university course i have to learn java. I am making a simple cyberpet type program i am storing each cyberpet in an arraylist. Each cyberpet contains a String name,int health, and int energy. All this is being stored in the arraylist. I ...

46. Include Arraylist in a parameter

47. arraylist

When you post code, wrap it in code tags. Don't create a new Scanner for every line of input. Factor out all that stuff about reading input from the LibraryBook class. It doesn't make sense as part of it. The class should represent a single book, not a book plus a bunch of ways to read input data. Instead, create a ...

48. How do I get an arrayList from an external class

I have 3 classes. 1 is used to create a contact object. 2 is for my GUI 3 Does all the buisness logic. I need to get an updated arrayList back from class 3 to display the contents in my GUI class. Can someone give me a snipet. I know hat to do from there so am only looking for code ...

49. Double ArrayList

I know you can make a double array by pulling a int[][] whatever; But is there a way i can pull a double array list. P.S. I did ArrayList> already and it seemed to work, but i don't know how i would set it to a 2 by 2 array. (I am trying to make a grid system.



51. arraycopy an ArrayList

Hi there, I was just wondering the best way of using System.arraycopy to copy an ArrayList. My ArrayList contains a list of customised Objects. Just a quick little bit of code would be great. thanks edit: the reason I ask this is because I'm unsure how to deal with it as it holds my own customised Objects. Edited by: JonBetts2004 on ...

52. ArrayLists that need to match.

53. Code works for both ArrayList and HashSet?

Ah, how silly of me. I must not have studied the API docs right... I remember searching through it for this and didn't see it for some reason. Thanks for clearing that obvious on up for me! RE: using the hashset/arraylist, that was one of the reasons I think I chose the hashset (I don't think it was set in stone ...

54. ArrayList data

Are you asking if you can store totally unrelated items in your list? Such as Cat objects, Bus objects and Triangle objects. If so you could make your list store but more importantly it smells of a bad design. If the objects are related such as a Student name and a test score then you could either use a Map ...

55. Help with an arraylist

i want to find the details of each of the objects in the arraylist but i want to find the people who are higher than the number that put in the parameter. I know i have to itterate through it but i dont know how to look at the variable. I know the rest of the code but not how to ...

56. new to Java- question about class ArrayList

public boolean addItem (String itemName) { String name= itemName; //ArrayList items; //items= new ArrayList (); //return items.add(name); return items.add(name); } } My problem is with the last method: addItem(). The compiler keeps giving me an error message about how it "can not find symbol- method add(java.lang.String); But I for the life of me can't figure out why. I created the ...

57. ArrayList

I'm trying to make a very simple Java App using arraylists. I need it to prompt me for names and take those names until the user types in done. Am I on the right track with my code at all? Sorry I'm just learning how to do this and am not very good at it yet. string nameInput; Needs to be ...

58. ArrayList

59. 2D arrayList

60. Using ArrayList

@Sir Horst The phrase "implement an interface" means "provide a class that implements the contract specified by the interface". Spot on... and very clearly stated. Good one. Ta. @MindPlay Google is your friend, google, google, google. Seriously... I just googled "java sort list" and the first includes links to the 1.4.2 API doco; articles fromexampledepot, javaworld, and; discussions of ...

61. ArrayList

Loko wrote: Please dont bother responding if it is a "waste of your time" i could do without the patronising and sarcasm. Look at it from our point of view. I took your question, "2 dimensional ArrayList", shortened it to "2d arraylist", threw java on the front of it, and within 10 seconds of reading your question I found the answer ...

62. Problem with javac and method return ArrayList

Hello guys! I am here because I am stack and the deadline of my coursework is very close Basically I have a method called inside the class called public ArrayList displayBooks(String choosenCategory) throws ClassNotFoundException which returns me the list of books. I tested this method and it perfectly works but when I ...

63. Lost , ArrayList

64. ArrayList question

Hi! I have an ArrayList instance and I do myArrayList.add(something) several times. After that I do something like for (Object obj : myArrayList) { do-something-with-the-object } My question is: will the for return my objects in the exact same order as I added them? I tried and it seems like the answer to this question is yes, but can I be ...

65. Array list help

66. ArrayList

yes, I am using a GUI and a JTable. what i have as far as a print method so far is basically the method taking a screenshot of the window displaying the JTable with the ArrayList data and printing out a screenshot of it. it is frustrating because the alignments and margins are always off and i can't just get it ...

67. ArrayLists in version 1.4

Hello I am using java 1.4 and I am having trouble with array list. I would like to access the uid variable within the object. Here is my code: public class MessageLog2 { String uid; String type; Date time; Date start; public void messageList (String xmlMessage) { try { JDOMEventV2 event = new JDOMEventV2(xmlMessage); this.uid = event.getUid(); this.type = event.getType(); this.time ...

68. Multidimensional arraylist

69. ArrayList Gotcha?

70. ArrayList Incomplete

Your code is not compilable and with your current formatting not readable. What you need to do is simply your problem so that it can be demonstrated with say 40-100 lines of compilable code so we can run the code and change the code if need be, an SSCCE. Also, when you repost, please make sure that your code indents with ...

71. arraylist matching

I have an arraylist of strings which contains entires :- a-b a-c a-b b-c b-f g-t the entries eg "a-b" is a string entry. it can be either break into 2 parts like "a" and "b". i want the output as :- the "a" has "3" matches " b, c,d" the "b" has "2" matches " c,f " the "g" has ...

72. Having trouble with my arraylist

public static String getName() { return setName; } We have a winner! This method is static. The setName variable is also static. What this means is that every instance of MMMPath shares a common variable setName and when you call getName() what you get is that common name. So whenever you create a new MMMPath it will set the value of ...

73. Bubble sort in ArrayList

74. arraylists

75. ArrayList issues

76. help with creating a method (arraylist)

77. Array List

78. 2D arrayList

I know little about this subject, but I believe that there libraries out there that allow XML (with a schema, I believe) to define their own classes so that all of this class information is in the XML / XSD and outside of the code that the reads the XML. But again, I'm speaking out of ignorance (hopefully soon to be ...

79. ArrayList Mystery

public String getWildName(){ Return RandIndex; } public void setTownName(){ RandIndex = TownName((int) (Math.random() * TownName.size)); } public String getTownName(){ return RandIndex; } public void setCastleName(){ RandIndex = CastleName((int) (Math.random() * CastleName.size)); } public String getCastleName(){ return RandIndex; } public void MainGame(){ Wilderness WE = new Wilderness(); Towns TE = new Towns(); Castles CE = new Castles();

80. ArrayList mystery, well to me...

public int getWildName(){ return WildName(RandIndex); } public void setTownName(){ //this method does what it's wild counterpart does, only at the different number range in the array index RandIndex = (int) (Math.random() * TownName.size); } public int getTownName(){ return TownName(RandIndex); } public void setCastleName(){ //this method doesn't take an argument either, remember that... RandIndex = (int) (Math.random() * CastleName.size); } public int ...

81. Help with Arraylist

82. ArrayList Help

83. ArrayList creation problem

84. adding transformGroup to ArrayList

85. A problem with an ADT and ArrayList

86. declaring boolan/integers ArrayList

87. arraylist

Hi guy, I am very confuse about the arraylist and I would like to check with you guy with my understanding with arraylist. 1) I understand that arraylist only hold object types and they did not hold primitive types right? 2) If you want to convert object type to primitive type you have to use wrapper class or casting is it? ...

88. ArrayList

my buddy and i are new to java, and need help with a program. the jist of it is that we created an arraylist that stores objects with 4 variables in each object. we want to consider one of the variables and rank the objects with respect to that variable. how could we go about doing this... meaning how could we ...

90. Using ArrayList

91. Help with ArrayList

public double correlation(Statistics other){ throw new IllegalArgumentException("mismatched n sizes"); } } I know this is just a skeleton of the program I am going to write. I was wondering what is wrong with my code so far. One constructor assigns the name of the variable this Statistics object represents, and an ArrayList of Double values (the initial data). The other constructor ...

92. arrayList / input problem

93. Help on ArrayList

/** * Creates a new movie to be added to the store collection. * @videoTitle is the title of the movie * @yearvideoProduced is the four digit year the movie was produced in * @videoPurchasePrice is the initial cost of the movie in cents * @videoRating is the rating of the movie between 0 and 5 * @rented boolean automatically set ...

94. how to declare array list in java.

95. ArrayList Help

This is just a simple prototype of the code. The problem i am facing now is that even though i have added objects to the ArrayList, i am unable to retrieve these objects in the ArrayList from another class. To make it simple, when i add 3 Cat objects to the catArray as shown in the code above, catArray.size() should show ...

96. problem with an array list

So here's my problem: I am trying to build a program that allows me to create an array list for each bank account in a bank. This list will keep track of each transaction by recording a deposit (positive number) or a withdraw (negative number). Is it possible to have an array list created with a variable in the constructor Public ...

97. need help with input fields & saving to arraylist

I am working on a program that asks the user for several different inputs. In one tab of the window it asks the user for a book's title, author and isbn number, each one has its own jtext field. Another tab asks the user for a movie's movie title and the cast of the movie, the title is in a jtext ...

98. Arraylist

99. ArrayList problems

The exact error message I get is: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 10 at Solver.unMove( My array at this point in time is 5x5. The arrayList can only get as big as however many elements are in my 2d array, which is 25 in this case. The 2d array is supposed to represent a checkerboard, and the arrayList represents the moves ...

100. ArrayList

Thanks! And example was just what I needed. I am still suprised that you have to write Integer instead of int but now I know that. What I dont get is why I sometimes see code that looks like my first code example, where there are used squarebrackets instead. Have I confused it with something else?  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.