All Questions
90 questions
0
votes
1
answer
58
views
How to map ArrayList elements with specific values and then print it
ArrayList<Integer> companiesId = new ArrayList<>();
int numberOfCompanies = 10; // Just for example
...
float profit;
Scanner input = new Scanner(System.in);
for(int i = 0; i < ...
1
vote
3
answers
135
views
Iterating in Arraylist
I am trying to iterate the Arraylist in java and I want the output as -
1 4 7
2 5 8
3 6 9
I don't want to use the for loop. I want to use 'for each' loop to iterate and get the desired result. I want ...
0
votes
1
answer
267
views
Using a for-loop in java to capture player names is outputting wrong number and skipping first player
I'm creating a game in java. I have written separate a method for capturing the number of players who are playing (which is working), and with the below method I am trying to capture their names, ...
0
votes
2
answers
110
views
Won't return object
private ArrayList players = new ArrayList<Player>();
public Player getPlayerByName(String theName){
for(int i = 0; i < players.size(); i++){
String pName = (String) players....
0
votes
1
answer
102
views
Alphabet Bucket 2
public static ArrayList<ArrayList<String>> hoops(ArrayList<String> a) {
ArrayList<ArrayList<String>> list = new ArrayList<ArrayList<String>>(26);
...
0
votes
1
answer
335
views
Alphabet Buckets
public static ArrayList<ArrayList<String>> hoops(ArrayList<String> a) {
ArrayList<ArrayList<String>> list = new ArrayList<ArrayList<String>>(26);
...
1
vote
1
answer
807
views
Finding the longest run of duplicate numbers in an ArrayList? (Beginner java)
This is my first time using stack overflow, so I'm so sorry if this is formatted incorrectly in any way. For a comp sci project, I have to do some different things to a 40-item Array List of random ...
1
vote
4
answers
5k
views
Usage of Iteration's .hasNext(); and .next(); methods in Java
For 2 days I'm pretty confused about .hasNext(); and next(); methods of Iteration interface especially in while loop. Let me give an example:
import java.util.*; // imported whole java.util package.
...
0
votes
3
answers
60
views
How can I convert this iterative statement into a recursive statement?
So I have this programming project in which I need to create a program that determines if a number is a perfect square, and if so, write it into a .txt document. This is very easy and effective to do ...
0
votes
4
answers
60
views
Java: I=How to use ArrayList.contain() within a single element
So I have some java code that needs to throw out every single element containing the number 5 and return the count. So far I have:
public static int noFive(int start, int end) {
ArrayList&...
0
votes
2
answers
108
views
Adding string user input into an array list based on how many iterations
I am working on a Java project and I have my Super class with private attributes. I use the accessors and mutators I inherited from my superclass inside Main to set and get these attributes. I am ...
0
votes
1
answer
20
views
Can you get IndexOutOfBoundException when the array list you are trying to iterate over is too large? Or is there something wrong with my loops?
I am trying to iterate over an arraylist with a least a couple thousands of entries in it. But I was given an IndexOutOfBoundEcxception instead. I've checked my iterative loops and can't really see ...
0
votes
1
answer
362
views
Why do my ArrayList of Arraylist values change back after I set them? [closed]
I'm working with an ArrayList of Arraylists of Arraylists of ArrayLists, unfortunately. I'm very new to Java, so this could be a simple mistake on my part (I'm used to Perl). I'm troubleshooting some ...
0
votes
2
answers
134
views
Selection Sort in Java Arraylist
I need help debugging my code. It keeps on making a mistake and I can't find out where. Here is my selection sort method:
private void selectionSort() {
int best = 0;
int j = 0;
...
0
votes
0
answers
14
views
displaying values in tabular format [duplicate]
displaying List in tabular format but somewhere I am doing wrong.
a.jsp
List<String> abc =
(ArrayList<String>)request.getAttribute("studentsrollno"); // got
studentsrollno from ...