How would I shorten this?
int[] a1 = {2, 0, 1, 4, 3};
int[] a2 = {3, 1, 2, 0, 4};
int[] a3 = {4, 2, 3, 1, 0};
int[] a4 = {0, 3, ...
|
I am adding elements to a ArrayList and it adds the first one correctly but then when I add any subsequent elements it wipes replaces the other elements with the value ... |
I'm trying to do a convex hull approach and the little problem is that I need to get all sets of three consecutive vertices, like this:
private void isConvexHull(Ponto[] points) {
...
|
I have `a string example = "this site holds all the examples from The Java Developers Almanac and more. Copy and paste these examples directly into your applications"
after token and ... |
I have a class
Class TextChunks extends Token {
ArrayList<Token> arrt = new ArrayList<Token>();
}
extent fron class :
class Token {
String s;
int frequency ...
|
I want to know if there's a way to run a method of inside an element of an Arraylist
but I don't want to do it with get because it actually changes ... |
Let's say I have a bean like below.
class Customer{
private String code;
private String name;
private Integer value;
//getters setters omitted for brevity
}
Then from a method I ... |
|
I have an ArrayList containing Movies.
ArrayList<Movie>movies = new ArrayList<Movie>();
Movie has a property int movienumber.
The user can select a movie according to the movienumber, by entering the desired number into the ... |
I'm currently doing my third year programming project and its a folio tracker. :/ I have crated Stock_API and Portfolio_API interfaces (and implementations of them) and a GUI class which when ... |
I want to create an Array that contains ArrayList elements.
I've tried
ArrayList<String> name[] = new ArrayList<String>()[];
but that doesn't seem to work.
|
I have an arraylist of objects with an age field internal to the objects. How can I sort them in ascending order dependant on their age?
Thanks for your time
|
Java's ArrayList dynamically expands itself when it needs to. How many elements does it add when the expansion happens?
And does it copy the old array into the new one, or does ... |
suppose I have arraylist of integers...is there a way that I can generate a random permutation/arrangement of the elements in the arraylist
so if the list is {1,2,3,4,5,6}
calling some method randomPermute() ... |
I'll try to explain this as best I can. I have an ArrayList of String's. I am trying to implement server-side paging for a webapp. I am restricted ... |
I have a string arraylist
ArrayList data = new ArrayList();
and I have stored string values inside. Now i want to do something like
data.get(0) == "a" (need to compare)
How can I do? please ... |
In TreeSet there is a method called contains that returns true if an element is in the set. I assume that this method uses binary search and does not iterate through ... |
I have a custom ArrayList interface that extends the Comparable class and is in ascending order. The class I'm working on is implementing this interface.
My problem is I need to edit ... |
I have two arrayLists with 3 integer. I want to find a way to return the common elements of the two lists. Has anynody idea, how can I achieve this?
... |
I'd like to perform a function on a a list of data in at text file but I'm not sure how to go about it. My understanding of how to manipulate ... |
How can I know the different element between 2 array list in java? I need the exact element not a Boolean value which can be retrieved using removeAll().
|
I have an ArrayList of String[].
Each String[] contains two values: value and date.
If I print it, it will look something like this:
value | date
-------|----------
357.0 | 2011/05/30
-234.0 | 2011/05/31
-123.0 | ... |
What is the most efficient way of finding a ArrayList element according to a "subelement"?
For instance I have an ArrayList named test that is made up of these Arrays:
{a,first}
{b, second}
{c, third}
{d, ...
|
Why does this line of code in my Tree class not work. I get an error on the add(child).
public void addChild(TreeNode<T> parent, TreeNode<T> child)
{
...
|
How to sort heterogeneous elements in a array-list? For example,
ArrayList l1 = new ArrayList();
l1.add(1);
l1.add("hi");
l1.add(1.0f);
Now how to sort this array-list?``
|
I am using an arrayList in one of my code. I am finding it difficult to retrieve elements out of an arraylist. it gives me an error when i use this: ... |
I have made a LinkedList to store State objects which is a class I have created. I can add states to the list as expected, but whenever I try the size() ... |
I'm familiar with the ways I can get an element position in array, especially the ones showed here: Element position in array
But my problem is I can't figure out how ... |
Say I have an ArrayList containing the elements {1,2,3,4}, and I want to enumerate all possible combinations of two elements in the ArrayList. i.e. (1,2), (1,3), (1,4), (2,3), (2,4), (3,4). ... |
I'm not sure how to say what I need so here's an example:
class Foo{
int x;
int y;
int z;
}
ArrayList<Foo> a;
The array has objects <a,b,c>,<a,c,d>,<b,c,e>,<b,e,f>,<c,e,f>,<g,h,i> etc
How can I retrieve all objects that have a ... |
I have a problem about Arraylists. I created an arraylist of user defined object. In my drawing program, I created a class which takes only this arraylist. In another class I ... |
I need to get the count of the most frequently occurring element in an arrayList of Objects. I have this code and it´s working.
public static int contarRepeditos(ArrayList<Objecto> a) {
...
|
Give me the alternative of elements() method is arraylist
|
Could anybody please tell me why i am having only one element inside the ArrayList called as items.
Only one element is being added to anArraylis while parsing XML.
This is my code
And ... |
I have two array lists, one for teams and one for players. The arraylist for players is in the teams class and I've successfully managed to get it so that ... |
I have an ArrayList containing Car objects and I want to get from that ArrayList all the unique names as String or just the Car objects that meet that criteria.
EG:
public class ...
|
How do I initialize the values of an ArrayList?
I found this on the internet, but it doesn't work.
ArrayList<Kaart>[] hand = (ArrayList<Kaart>[]) new ArrayList[AANTALSPELERS];
All elements of hand are null. I get ... |
I want to extract particular elements from an arraylist. eg: If arraylist contains elements : Rajkumar , Shashii , Hari Kumar , paters , nam kumar I want to take elements ending with kumar i.e. Rajkumar, Hari Kumar , nam kumar How can i do it through efficient coding Thanx in advance |
I have code which returns a database query as a list. I need to be able to select individual elements of this list and place them in an html table. for (ListIterator i = empList.listIterator(); i.hasNext(); ) { //out.println(" | "+i.next().get(0)+" | "); //above doesn't work, below works but only returns all 8 elements of list out.println(" | "+i.next()+" | "); } In the above code, I'd like to ... |
A bit of a dumb ass question, but how do i get the individual elements from the following array, Table and row ArrayList row = new ArrayList(); ArrayList table = new ArrayList(); int i=0; while (rs.next()){ row.add(0,rs.getString("product_id")); row.add(1,rs.getString("name")); row.add(2,rs.getString("description")); row.add(3,rs.getString("long_description")); table.add(i,row); i++; } row = null; // this is in my jsp ArrayList data = product.getProductList(); int size = data.size(); //int ... |
|
Hi, in java, primitives types move with pass by value but other types(Object Types) with pass by value of their references. There is a question at this point. if we have got an arraylist with element of strings why don't we change the arraylist elements? a sample code: ArrayList a = new ArrayList(); a.add("istabul"); a.add("Ankara"); a.add("Denizli"); if we take a new ... |
I have an arraylist, clientList, which holds an array of clientRecords which has a string value of a sequence number. I also have an arraylist, policyList, which holds an array of policyRecords which has a string value of a sequence number. I am trying to figure out how to compare the two sequence numbers against both arraylist? ArrayList clientList ArrayList policyList ... |
I have an arraylist, clientList, which holds an array of clientRecords which has a string value of a sequence number. I also have an arraylist, policyList, which holds an array of policyRecords which has a string value of a sequence number. I am trying to figure out how to compare the two sequence numbers against both arraylist? ArrayList clientList Object[0] clientRecord ... |
Hi all, I have a class say XYZ which contains a method getSFInGroups() and this method returns an ArrayList within an ArrayList in the form of [GroupName , ArrayList[EventName,SecurityFunctionVO]]. My question is how can I access the individual elements of this Arraylist, like GroupName, EventName and the various fields inside the SecurityFunctionVO class which is a value object. Thanks. |
|
Well, it really depends on what kind of objects are you storing, and how should they be compared, how do you tell which objects are the same, or which should come before or after another. If you're storing String objects and can sort by the normal English natural order, Collections.sort is fine. If not, you should implement your object's equals & ... |
hai you can use Comparator class.It is very useful and interesting working on it. i created one class by implementing this.we can sort the objects in it by the property of the object also.So try it.you should use reflection package for getting method to access the property value.Very easy and interested one. |
Hi everyone, could anyone here please explain to me how to search an arraylist and return the smallest element from it? I know I need to search through the arraylist and do a compareto on each element, but not sure how to write it. [ March 06, 2007: Message edited by: big momma ] |
|
|
I have a a list called commonList.getCommonListItems. In this list I have multiple elements and I'm needing to sort by 2 elements within this list: first by binSortCode and then by itemDescr I've been googling and trying to get some help but am having problems trying to understanding comparable vs comparator. I had used comparable to sort on a single element ... |
Hi. I'm making a program that stores information about football players. The program makes it possible to create new players and register match statistics about them, such as goals, minutes played etc. The program works quite well, except for the part where the program has to check if an element (player) already exists in the arraylist, so that the program doesn't ... |
Dear all, I have a problem taking selected elements from 2 different arraylists placed in each class.. i am currently unable to put in one of the elements from another arraylist.. Desired output Account Number Balance Customer Name 1001 100.0 Jack 1023 200.0 Rob 1729 300.0 Jon The codes.. import java.util.ArrayList; public class MainArray { public static void main(String[] args) { ... |
|
|
|
I am executing a JPA createNativeQuery, which returns a set of customer numbers that match user-defined selection criteria. For some reason, createNativeQuery doesn't like it when you specify java.lang.Long as the class. It complains about not finding the descriptor. So, the default return type, when this query is executed is BigDecimal. Well, for reasons I won't go into, I need the ... |
Hi, i have a blackSuffix List which includes some file extensions like "ico png jpg jpeg mov avi" etc. I also have a ArrayList which has about 500 links and i want to filter out all elements that end with a blackSuffix for (int i = 0; i < links.size(); i++) { String x = (String) links.get(i); for (int j = ... |
Looks straight forward- But has a catch because the process has to be continued until the elements of the list have been exhausted- One has to remember the last index, repeat the loop to complete all the elements of the list. You would have to first identify number of iterations so that you can completely traverse the list. And for each ... |
thanks for the reply. can we use add() if the user add new elements using keyboard. public static void addStudent(int index, ArrayList students) { //ArrayList students = new ArrayList(); System.out.println("Add a new student"); Scanner input = new Scanner(System.in); //ArrayList students = new ArrayList(); System.out.println("Enter your name:"); String name = input.nextLine(); System.out.println("Enter your student ID:"); String studentID = input.nextLine(); System.out.println("Enter year of ... |
Hi, I am really struggling to get this to work, My problem: I have a class that holds details of items. These items are then added into another class as an arrayList. I have a 3rd class that acts as a cash register that scans barcodes. I want these barcodes to match the arrayList barcode then get the details such as ... |
Like the title says. If I put an object like a string, int, long, or even a custom object into an array list how big can it be without it returning an error? I'm not asking about the maximum size of the list but the individual element(s) going into the list. I know that a string object can't be larger than ... |
public static void testPOS(ArrayList vie, ArrayList tag) { for (int i = 0; i <= tag.size(); i++) { System.out.println("i is: " + i); System.out.println("tag.get(i) is: " + tag.get(i)); System.out.println("tag.get(i + 1) is: " + tag.get(i + 1)); if (tag.get(i).equals("A")) { if (tag.get(i + 1).equals("R")) { Collections.swap(tag, i, i + 1); } } } |
Hi So i got this problem, i need to filter out bad results into an another arraylist. I need to remove the entry from the first list (bookGood) and add it too the second (bookBad) but already when i try to remove elements from bookGood i get java.lang.IndexOutOfBoundsException anyone got any tips on how you could manage this? Another thought was ... |
Hi, I have some check boxes to add selected days of a month to an arrayList, when i select the element it gets added, but when next time i add other elements, it shows arrayList empty and add only the selected element. // this is my class to implement actionListener public void actionPerformed(ActionEvent e) { JCheckBox obj = (JCheckBox) e.getSource(); String ... |
|
Hi... I make an arrayList to store my objects. And I want every time the user will put the new object, the program will selection the arrayList first. It will see whether the new objects are same with the object inside the arrayList or not. If it is same then that object will not be put into the arrayList and there ... |
|
|
how to compare the elements of the two arraylists al1,al2 Let's say we have the following two lists: al1=[10, 20, 30, 40] al2=[11, 12, 13, 14, 15,16,17,18,19,20] we have to compare 10/11,10/12,10/13,10/14,10/15,10/16,10/17,10/18,10/19,10/20,11,11,11/12,11/13,11/14,11/15,......................like that all the elements so that we have to compare every element in the first list to every element in the second? |
|
|
|
|
|
|
|
|
|
I assign value to the "quantity" see below public static class Entry { String subString; int quantity; String breakdown; int [] numberOfbrds; } Then I use this class: public static void main(String[] args) { ArrayList hashTable = new ArrayList (); Entry hashEntry = new Entry (); // here I assign some values to the variables of hashEntry hashEntry.subString="ggggggg"; hashEntry.quantity=9; ... |
basically, i am trying to code a game which uses balls of dfferent colors. each of the balls has a value. I have therefor created a class called ball with color and value as instance variables. now i need to create a pool (ArrayList) of these balls. How do i go about it? thanks sammie |
Hi all most likely me having a blonde moment, but what is the best way to pull a specific object out of an ArrayList based on one of it's properties ? That is to say I have an ArrayList which I will call al. In al there is objects called obj1, obj2 ob3 etc. Within each object is variables v1 v2 ... |
|
|
Hi! Does anyone know what should I use in order to find out how many elements(i.e.objects) are identical in an Array List of objects? Is there any predefined method in the Array List that does that, except "boolean contains(Object elem)" which identifies weather the element exists or not in the ArrayList? Any comments are appreciated! Thanks! Radu Paltineanu. |
|
|
I have an arraylist of arrays. I now need to create a separate list that contains unique combinations of only 3 values contained in the underlying array in the arraylist. I think I can use a HashSet. I am just not sure how to create the HashSet? I could create an ArrayList of just those 3 values and then use the ... |
Short answer: No, in Java, references point at objects, not memory locations. Long answer: No, unless you want to mess with your design a bit. What you could do is wrap your values and keep a reference to this wrapper. When you update an object in the arraylist, just change what the wrapper is wrapping, don't replace it in the List. ... |
|
drakester wrote: This is the code I have and it's not updating the previous element in the list with "D" and I have no idea why? That code looks correct enough. There are a couple things you're doing which are unnecessary: You don't need to check for a null previousAccountNumber - assuming accountNumber isn't null (which it isn't or you'd have ... |
If you have an arrayList of Strings, it will use string comparison rules to decide what is max. If on the other hand you were to use an ArrayList if type Integer (hint, hint), then it would use number value for its comparison rules, and I have a feeling that this is what you want. |
|
I have a arraylist like: ArrayList extends myclass> myobj and I need to swap two element of myobj. so i used: Object temp = myobj.get(fst); myobj.set(fst, hotel.get(scn)); myobj.set(scn, temp); but the method set doesn't work. the error message is: The method set(int, capture#2-of ? extends Hotel) in the type ArrayList is not applicable for the arguments (int, capture#3-of ... |
|