I need some help. I want to create a for loop that creates n number of objects of a class, and then adds them into an arraylist. Something like this:
//Player is ...
|
My problem is as follows. I have an arraylist of integers. The arraylist contains 5 ints e.g[5,5,3,3,9] or perhaps [2,2,2,2,7]. Many of the arraylists have duplicate values and i'm unsure how ... |
I'm reusing the same ArrayList in a for loop, and I use
for loop
results = new ArrayList<Integer>();
experts = new ArrayList<Integer>();
output ...
|
I'm iterating through an ArrayList, modifying the string, and trying to add it to a new list. It doesn't change the original list. Within a foreach loop in Java, ... |
I have set up a HashMap like so:
Map<String, ArrayList<String>> theAccused = new HashMap<String, ArrayList<String>>();
... and I populate this by storing for every name (key), a list of names (value). So:
ArrayList<String> saAccused ...
|
this is my first question on stack overflow but I have some experience in Java. I am making a Java application at the moment (575 lines and counting!) and am trying ... |
I'm encouraged by so many warm-hearted Java experts that I dare to throw another question today for help (all my questions are from real life projects - and since I'm ... |
|
In Java how to traverse an ArrayList without using any looping constructs ?
|
Currently I have two classes. A Classroom class and a School class. I would like to write a method in the School class public void showClassRoomDetails which would find the classroom ... |
I have a file with data in the form timestamp, coordinate, coordinate, seperated by spaces, as here;
14:25:01.215 370.0 333.0
I need to loop through and add the coordinates only to an ... |
I need to write a method that loops through ArrayList pathClientStatic and then copies certain elements to a String[].
pathClientStatic is an ArrayList containing a string of timestamp x y
Each is ... |
I want ask why Java heap space is triggered when executing "NAME.add("Tom");"?
<%@ page import="java.util.*" %>
<%
try {
ArrayList <String> NAME = new ArrayList<String>();
int count= 0;
...
|
I'm reviewing for an exam. A question on an old test was to: Using an interface, write a method that applies an arbitrary method to every element of an ArrayList. Both ... |
Today I was happily coding away when I got to a piece of code I already used hundreds of times:
Iterating through a Collection (here ArrayList)
for some reason I actually looked at ... |
I need help writing a for each loop which searches through an array list called peoplelist of type people. The loop needs to search for the values String postcode and String ... |
Ok so i'm working on adding a list of about 120 or so specific arrays into an array list
(These are just hypothetical values and names, but the same concept
private ArrayList<int[]> listofNames ... |
Please help me to create a loop through LinkedHashMap<String,ArrayList<String>> h:
if (h.get("key1").size() == 0)
System.out.println("There is no errors in key1.");
...
|
I am new to Java.
Is there possibility of sum of ArrayList without looping?
PHP provides sum(array) which will give the sum of array.
The PHP code is like
$a = array(2, 4, 6, 8);
echo ...
|
I have a SQL query that returns a number of results (unfortunately, the number of results will vary). Currently, I am storing the results into an arrayList like so:
ArrayList allTerms ...
|
I have a bean class containing two variables Title and ID.
public class Bean(){
private String title;
private String ID;
}
I also have two arraylists of type ... |
In the code below
// Assume there are non-null string arrays arrayA and arrayB
// Code 1
ArrayList<String[]> al = new ...
|
This is a simple exercise from Chapter 2 of the Sun Certified Java Associate Study Guide that i'm having trouble with. When I try to compile the class below, I get ... |
Im a beginner in java and starting to do test driven development. I have a pretty basic scenario i am stuck with. I want to pass a string of numbers from ... |
So I am writing a class that plays the card game war. I have already made separate classes for the hand, the deck, and the different methods that go along ... |
I'm learning Java programming and right now I'm exploring the use of objects in arralist. I know how to get a single value out of a object that are in a ... |
|
Hello. If someone could please tell me why I am seeing different results with the following code: /** * This works fine... */ SomeObject [] s = new SomeObject[2]; s[0] = new SomeObject(); s[1] = new SomeObject(); s[2] = new SomeObject(); s[0].setSomething("Some value here"); s[1].setSomething("Another value here"); s[2].setSomething("And yet another value here"); /** * But this only stores the last value ... |
|
I just can't seem to get my head around how to iterate through an arraylist of arrays. I get as far as, for example: details - arraylist of object Details that has a field named Data, which is also an arraylist. Data stored arrays in the arraylist. count - an outer loop i'm using to iterate through all details arraylists. for ... |
Hi Gregg, many thanks for your prompt reply ! I have since discovered that the problem has nothing to do with 'Java' but with the fact that I am using Eclipse which as standard only supports Java up to 1.4. I have tried unsuccessfully to install the 'Cheetah' plugin - get the error that the org.eclipse.jdt (3.0.0) is required - as ... |
Dear All, I have a Multimap which stores string,integer and list as a value to the keys. Below is code that I tried. But the problem is I want to get the values for the list too. I have showed the output that I am getting and the output that I am looking for. import java.util.Collection; import java.util.Iterator; import java.util.LinkedList; import ... |
I want to initialize arraylists inside a loop instead of initializing it one by one. is that possible? the number of arraylists will depend on the user input, so for example the user input a value of 50, i want to simply initialize it inside a loop and will do the initialization of the arraylists.. how will that be possible that ... |
|
I'm writing a program built to store, retrieve and sort data for assignments. I've got most of the code down fine, I've got a seperate Assignment class with .get and .set methods, and everything has been working fine, but in my main program, I'm trying to remove an entry. The program seems to just skip over all the code I've got ... |
|
After staring at the debugger like a Hawk, I figured out where the problem lies. You guys were right ! the Stack [s] was empty after all !!!!!! Here's where the problem lies. Java Code: // A variable called [neighbours]. It represents the neighoubrs of the current node in the loop ArrayList> neighbours = g.get(x); // The Path [p] represented as ... |
for (Animal animal: zooAnimals) { Above is a for-each loop. int i = 0; i <= zooAnimals.size(); i++ Above is a normal for loop (missing the for keyword). Use one or the other. Don't try to jam both together. The for-each loop advances through the list for you. Each time around the loop the next Animal object in the List is ... |
We now made a function getProtein. And what getProtein does is he takes every >seq and the lines below. Now the idea was something like this: int count = 0; // Do something to continue to the next with getProtein function (>seq2 etc.) count++; Do you maybe have any idea on this one? Like how to get the next >seq... |
Hi :) I am first year student of Computer Science. Recently I was doing a small project for Java programming exercises. My lecturer wanted me to do the library class using the ArrayList collection and for-each loop anywhere I could implement it. I have done it properly but I am not satisfied with this solution. I have one for-each loop which ... |
k i have an array list of integers - 0-9 in different order. i have a gui with 10 labels and a button. what im tyring to do , is create a for loop that will set the array list to those 10 labels, . how would do this .? do i have to make an array list for the labels ... |
|
i have never come to a forum for help like this, and i have been working and testing and compiling for hours now. please don't think i'm looking for an easy way to finish this. i'm just stuck and can't find any examples that fit what i'm doing in my textbook or online. any help very much appreciated. humbly yours, scott ... |
|
I've always considered arrays rather simple and understandable structures myself...especially one with only 5 "columns" If creating an arraylist of objects actually will easily solve the problem I am having I will do so. But I don't understand how it would help...I still need to change individual elements of a repeating set of arrays...or objects....and I don't see what is wrong ... |
|
|
|
I have been trying to figure out how to make this code work. I have an ArrayList of ItemOrder object.s ItemOrder is a class with the following constructor and method public ItemOrder(Item item, int quantity) { this.item = item; this.quantity = quantity; } public Item getItem() { return item; } In my ShoppingCart class ( that implements an ArrayList of ItemOrders ... |