Tagged Questions
-3
votes
1answer
55 views
New ArrayList with same values
I have an ArrayList:
ArrayList<Integer> example = new ArrayList<Integer>();
example.add(1);
example.add(1);
example.add(2);
example.add(3);
example.add(3);
So I want to make others ...
1
vote
2answers
34 views
JPanel, instantiate an array of JButtons
I am having trouble putting my Panel class to my main class. I can't seem to instantiate and register the buttons to the actionPerformed method. This is project is suppose to use a grid layout with 9 ...
0
votes
1answer
11 views
solrj error: array out of bounds
hi im trying to run this code and i can seem to figure out what is wrong..sorry im new to solrj
import org.apache.solr.common.SolrDocument;
import java.util.Map;
import ...
0
votes
4answers
43 views
Read and split text file into an array - Android
I have gone through loads of these questions but still cant seem to figure it out. I have a text file split into rows. Each row consists of 5 pieces of data separated by a ",". I am trying to read ...
0
votes
1answer
36 views
Sqlite columns to string array
How can i put every column from an android sqlite database into a different string array ?
I have a database with 4 columns :id,one in which i store the date,another for the hour and another for a ...
0
votes
3answers
39 views
Cant understand why this doesn't print to the text file
Im coding a hotel reservation program and im using a GUI to input the Guests info into TextFields. I have an array where these input values should go straight to (maybe thats my problem, but donno how ...
4
votes
2answers
44 views
What code and how does java.lang.reflect.Array create a new array at runtime?
I looked into Java source code and the method is like follows:
public static Object newInstance(Class<?> componentType, int length)
throws NegativeArraySizeException {
return ...
0
votes
1answer
18 views
Merging 2 Images Using 2D Arrays as Pixels
I am trying to merge two B&W images based on the following parameters.
The new created array use the largest of the two image's width and height as it's own. The int at a specific point in the ...
-2
votes
2answers
60 views
Java 2-d array I/O
Ive had some problems writing out my stored data from my array to a text file.
I've managed to get some kind of data in the file but I've had problems understanding what it really is (is it ...
0
votes
2answers
65 views
End of string character in Java
I was solving an easy question :
Remove certain characters of a character array in Java , the idea is straightforward :
static void remove_char(char[] arr, char c){
int r = 0;
for (int i = 0 ...
-3
votes
0answers
30 views
coding task - find largest switching slice in O(N) time [on hold]
Given an int[] find the length of the largest switching slice.
A slice is a consecutive number of elements of the array e.g. A[0] to A[3].
A switching slice is a slice where the numbers repeated ...
1
vote
1answer
44 views
expand java 2d array at left and right [on hold]
I have 2D java array, for example:
int[]][]arr = {{1, 2, 3, 4, 5, 6}, {7, 8, 9, 10, 11, 12}}
I want to copy several left and right columns of this to right and left sides of my array. This my ...
-2
votes
0answers
46 views
Removing one item from an array in java [on hold]
I have an inventory system and it has a few items of the same name:
p.addNewItem("Human Arm");
p.addNewItem("Human Arm");
p.addNewItem("Human Arm");
How do I remove one 'Human Arm' but keep the ...
0
votes
3answers
78 views
Java, Return true if array contains duplicate values
I am trying to have a method (duplicates) return true if a given array called x (entered by user in another method), contains duplicate values. Otherwise it would return false. Rather then checking ...
-1
votes
1answer
48 views
How to print String data as a table in java GUI [on hold]
I am going to create a table in java GUI and I have found below example:
String[] columnNames = {"First Name",
"Last Name",
"Sport",
...
0
votes
1answer
37 views
Java dynamically generating various field types from a given array list
I'm trying to build a form generating class and i might have hit a glitch somewhere in my logic statement.
You have two string arrays.
String[] fieldNames;
String[] fieldTypes;
Both their lengths ...
-1
votes
1answer
49 views
How can I make my screen render a bigger tile for my tile game?
public void render(int xp, int yp, int tile, int colors, int bits) {
xp -= xOffset;
yp -= yOffset;
boolean mirrorX = (bits & BIT_MIRROR_X) > 0;
boolean mirrorY = (bits & ...
0
votes
3answers
66 views
Sort two arrayLists concurrently
Say I have two ArrayLists:
name: [Four, Three, One, Two]
num: [4, 3, 1, 2]
If I do: Arrays.sort(num), then I have:
name: [Four, Three, One, Two]
num: [1, 2, 3, 4]
Is there any way I can ...
0
votes
1answer
47 views
Java - Zero out the rows/columns of 2d array if it contains a target number
Given a mxn matrix that looks like this:
1034
1234
3560
Need to output something like this:
0000
1030
0000
*Target number is 0.
Here's my solution, but I think it's not very efficient (both space ...
-3
votes
1answer
48 views
running an algorithm without a Main class?
I'm learning Java from Introduction to Java Programming 9th ed. by Liang Y. D. and having some difficulty with one of the examples, pertaining to arrays. I would like to execute a sorting procedure ...
0
votes
3answers
53 views
Class Inheritance in Java
I've been working on a basic class inheritance exercise, and even though I think I've got the jist of it, my program isn't working the way it should. I'm getting compile errors and haven't been able ...
0
votes
2answers
38 views
How to call your enum using a for or while method in java.?
So i am trying to use a for or while method, to print out all of the objects in the main method.(Anna, Courtney, Ashley)
public class JavaApplication56 {
public enum details {
...
2
votes
3answers
41 views
Adding Elements From Each Row of Jagged Array
I am trying to get every single combination of elements in a n-row, jagged 2d-array of strings by using only 1 element from each row.
An example array (With each line representing a row in the ...
0
votes
3answers
40 views
how to get element position in 2D array when mouse clicked?
Im building a board using GUI(may be board game). I have created 2D array to make cells like Gomoku game. I want to make this function: Whenever i click a cell, the cell position will be displayed.
...
0
votes
4answers
32 views
An array of UIImageViews in objective-c
I already had many UIImageViews.. I want to make an array of UIImageViews and assign every element of the array with one of the UIImageViews above.. How can I do that with objective c??
I did it in ...
-1
votes
3answers
49 views
Is there a method in Java that lets you find the index of an element in an int array? [duplicate]
I need to assess the last int in an array where a certain conditional is met. My program can work out what that int is, but it needs to also know where it's position was in the array. I searched on ...
0
votes
1answer
34 views
2d Integer array not running properly java android
I am using an array like this:
int selIntIndex = Integer.valueOf(selStringIndex);
int[][] PreIntVal = new int[][]
{
{ selIntIndex,
...
4
votes
6answers
106 views
Why can't we create an array of “Concrete” class inside a generic class?
public class GenericClass<T> {
class MyClass {
}
public GenericClass(final T[] param) {
MyClass myObject = new MyClass(); // OK
MyClass[] ...
0
votes
0answers
22 views
Reading an integer array from DataInputStream [duplicate]
i'm trying to load some useful data for my android app. All the data are some integers(such as highscore, etc). I've already saved it on a file using this:
int[] numeros = new int[5];
for(int ...
0
votes
2answers
40 views
List of Thread and accessing another list
I've already made another question close to this one several minutes ago, and there were good answers, but it was not what I was looking for, so I tried to be a bit clearer.
Let's say I have a list ...
1
vote
3answers
75 views
Pig Latin Translate (Sentence)
I am making a Pig Latin translator and I don't really knwo where to go from here. I have the basic code, but I need to revise it in order for it to translate a whole sentence. If anyone can tell me ...
0
votes
2answers
81 views
Creating Array or ArrayList from class ojects
I have been working on this for a while, but can't quite seem to figure out how to add an item to an ArrayList. I would like to add grocItem (should be 7 grocItems from user input from for loop) into ...
0
votes
1answer
56 views
Array returned using method reading Column names from MySQL database is full of “null”
I am writing a webservice using Java to communicate with a database that I have set up on a MySQL server running on my localhost machine. My method,ListColumns(), to look up the names of the columns ...
-1
votes
2answers
29 views
“Actual or formal argument lists differs in length”
When I try to put something in the () brackets of "Friends f = new Friends(friendsName, friendsAge);" it comes up with the error: "Constructor Friends in class Friends cannot by applied to given ...
-4
votes
2answers
47 views
Object position in array [duplicate]
I have an array of Objects. Now my question is how I can find out what position the object is in from within it?
My object array
public myObject[] objects = new myObject[10];
The constructor of ...
0
votes
2answers
59 views
String Array in res/values/strings.xml
I would like to know how to create an array of strings inside strings.xml, and how to access it in java code. I need this in order to use the setText(). Please help.
-1
votes
5answers
47 views
How do you isolate each number in an int and put it into an array? [on hold]
For example, let's say the user enters: 2314. What is the quickest way to take each number and put it in its own field in the array?
I have tried converting into a string and then isolating each ...
0
votes
1answer
58 views
Array allocation [duplicate]
I am confused what does that mean ::
int[] array = new int[0];
How many bytes are allocated here? Or nothing is allocated in memory? What is going underneath?
0
votes
3answers
81 views
compare 2 arrays and remove duplicates ? Java
so I am trying to compare 2 huge lists of text in java . The texts might look like this :
list1 : value 1 , value 2 , value 3 ...
list2 : value 1604 , value 7000 , value 1 ...
The point is I like ...
1
vote
4answers
98 views
Quicksort Algorithm in Java
I am trying to implement the quicksort algorithm in Java:
// Sort parallel arrays with quick sort
import java.util.Scanner;
import java.text.DecimalFormat;
class FunRunQuiSort {
static int ...
0
votes
2answers
66 views
Java: how to have an array of subclass types?
Say I have a super class "Animal" and subclasses "Cat", Dog, Bird". Is there a way to have an array of subclass type rather than class instances with which I'll be able to instantiate instances of ...
3
votes
3answers
100 views
Are there any generic version of Array.newInstance?
I noticed that in Java Array.newInstance() returns Object, rather than T[]. It is understandable as this method was introduced before Java supports generic types.
However it is a surprise that there ...
0
votes
2answers
56 views
Trying to get a Yes // No prompt to work. Will not take in a response
void searchForPopulationChange()
{
String goAgain;
String response;
int input;
int searchCount = 0;
boolean found = false;
boolean search = false;
while(search ...
3
votes
5answers
76 views
Creating an Array from multiple user inputs of different types
How I would get the 3 items from user input Item (name, cost, priority) into one object item and place that object item into an array of other objects?
public class Main {
public static void ...
0
votes
1answer
76 views
Looping an array
void searchForPopulationChange()
{
String goAgain;
int input;
int searchCount = 0;
boolean found = false;
while(found == false){
System.out.println ("Enter the ...
0
votes
1answer
22 views
Searching an array for specfic numbers and printing out all corresponding variables
void searchForPopulationChange()
{
int input;
int searchCount = 0;
System.out.println ("Enter the Number for Population Change to be found: ");
input = scan.nextInt();
...
0
votes
2answers
37 views
Java - Casting ArrayList<Object[]> to Object[][]?
Ok, so here's a small problem I'm facing - is there an easy way in Java to cast
ArrayList<Object[]> array;
to
Object[][] data;
?
1
vote
5answers
64 views
Create a new array index if it doesn't exist
Say I have a String like below
String s1 = "test1=1&test2=2&test3=&test4=4";
Pls note the test3 parameter in the string S1 as it doesn't have any value
String [] splitS1 = ...
0
votes
6answers
91 views
Using an array to store input from the user
I'm currently working on this project:
Create a simple Friends class with, as a minimum, the following:
-name and age fields
-appropriate constructors
-get/set methods
-toString() method
Create ...
0
votes
3answers
37 views
Not calling method from inherited class
In this instance I have 3 classes. Method class, Book class, AllBook class class.
AllBooks extends book class. Methods class is where most of my methods are (duh). I am having problems with only one ...