Tagged Questions
0
votes
1answer
21 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
30 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
53 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
83 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
36 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 ...
1
vote
1answer
21 views
Porting PHP array data structure into Java
I'm working with this data structure in PHP
Array
(
[leigh@bla] => Array
(
[chat1] => Array
(
[0] => Array
(
...
0
votes
1answer
28 views
How to store multiple byte arrays
I am working on a camera app, I take my picture and the data is gathered as a byte[]...I don't want to store the images on the phones memory, what I want to be able to do is store the byte array for ...
0
votes
7answers
74 views
Adding ints to an array in Java
I am trying to create a random number to add to an array (arr). I have looked around for answers but they all seem to not be working or be outdated. Here is what I have tried:
int[] arr = {};
int ...
0
votes
1answer
31 views
Cannot retrieve a Float array from a hashtable
I am limited to using legacy collections in Java.
I created a Hashtable
private Hashtable dataStock = new Hashtable();
and one of the entries of this hashtable is a Float array
...
-4
votes
3answers
53 views
How i could save an array[] to an array[][] with two dimensional
I had create an Array[] and i would like to save it in firsti column! So i had wrote this code:
String[][] SundaySounds = {{"0","0"}};
String[] SundayArray = {"0"};
........
for (int ...
12
votes
2answers
369 views
One-liner to count number of occurrences of String in a String[] in Java?
I have an array of String:
String[] myArray = {"A", "B", "B", "C"};
Is there a quick way to count the number of occurrences of a string in that array? Yes, I know I can iterate and do the count ...
2
votes
5answers
46 views
Java invoking a method with array parameter
I wrote the following function:
public void enterlessonnames(String[] names)
{
String msg="";
for (int i=0;i<names.length;i++)
{
...
0
votes
1answer
23 views
Differences between BufferedImage pixels and Color.getRGB() pixels
I'm trying to get pixel data from a bufferedimage that will only contain a gray scale translucent image (argb).
I'm getting a WritableRaster from the image and setting its pixels using the Raster's ...
-14
votes
0answers
43 views
multiple array by 2 and subtract by 1 and get all values of array to 0 in java [on hold]
You are given an 8 × 8 table of natural numbers. In any one step, you can either double each of the numbers in any one row, or subtract 1 from each of the numbers in any one column. Devise an ...
-2
votes
5answers
67 views
Explain this code (not getting the result i need)
package javaapplication54;
public class JavaApplication54 {
static int monkey = 8;
static int theArray[] = new int[1];
public static void main(String[] args) {
// i attempted two ways to try to set ...
0
votes
1answer
30 views
Save a LocalDate list to an array[][]
I would like to save the dates from the list to an array[][]?
My list is
List<LocalDate> dates = getWeekendDates
(new LocalDate(year, month, (day+2)), new LocalDate((year+1), nymonth ...
1
vote
5answers
64 views
Rearranging array when it has a null position
I have this code that searches one object in an array and removes it. I'm having a problem with its position, since some other methods work with this array (and it gives me a NullPointerException ...
0
votes
2answers
70 views
Looking for duplicate values in a 2 dimensional array
The assignment I am working on requires that I create a Sudoku game without using any classes, methods, encapsulation, etc. I am new to Java so bare with me. I am having trouble validating that the ...
-2
votes
1answer
48 views
Working with computing changes with Arrays
I am trying to compute changes via java programming --> Parallel arrays.
For some reason i keep getting "0s" as my output. But the rest of the program runs fine.
Here is the part of my program where ...
-3
votes
3answers
78 views
How to get the max number in all sliding windows of an array? [on hold]
Given an array of numbers and a sliding window size, how to get the maximal numbers in all sliding windows?
For example, if the input array is {2, 3, 4, 2, 6, 2, 5, 1} and the size of sliding windows ...
-1
votes
2answers
95 views
java all values int[] 0
For a minigame written in java, I have a main level and a background level. The player is only able to walk in the mail level, and the background level is solely for decoration. Ive written a method ...
-3
votes
3answers
70 views
Checking if a string contains any of the strings in an array
Without for () loops such as
for(int j =0; j < array.length; j++)
{
}
I want to be able to check if a string contains any of the strings in an array globally. So for() loops ...
0
votes
5answers
46 views
How to create an array that extends itself dynamically?
How to create an array that extends itself. I don't want to use the classes like ArrayList and Vector etc to do this. Instead i need to generate an array that extends it's size upon adding elements to ...
0
votes
2answers
58 views
putting double value 2d array read text
I want to put my text's double values on 2d array. My text is double and string together
deneme deneme 4.5 5.5 6.6 7.5 9.9 9.9
dsdsa sddsf 9.9 8.7 7.5 8.8 4.4 6.5
ı extraxt double from string. my ...
0
votes
3answers
43 views
Write a Java program using single dimensional array. Have a list of 10 numbers and fetch a value based on the index
So I have this assignment for my Programming class, and I'm lost on what to do for the second part. This is the code I have so far:
class SingleArray
{
public static void ...
0
votes
0answers
33 views
LCM of all the numbers in an array in Java
I have an array of ints, and I'm trying to find the LCM (least common multiple) of all the values in the array. I've written an lcm method separately; it takes two values as input, and returns the ...
0
votes
3answers
66 views
cannot find symbol - out of bounds error
I'm working on a class assignment. Basically, we must use one-dimensional arrays to display a student's name, his current grade, and the subject. Code follows:
import java.util.*;
import ...
0
votes
3answers
46 views
.class expected error when passing array to function
public class AssignmentChapter8
{
public static void main(String[] args)
{
int randomNumbers[] = new int[100];
int oddCount;
int evenCount;
for(int x = 0; x ...
0
votes
0answers
67 views
Java array data structure
How do Java arrays stay in the memory? I can't seem to find this information anywhere.
I am trying to optimize some really process-intensive algorithm for Android, and the only alternative left is to ...
2
votes
4answers
52 views
Random array-word generator [duplicate]
I'm trying to make a random generated array word, i dont find any problems with this code, but it just doesn't run, it doesn't show me the array's word when there is a random generated number. What is ...
0
votes
1answer
68 views
ClassCastException: java.lang.Object[] cannot be cast to java.lang.String[][]
I'm having a problem with Android when passing a 2d array to another activity. I have no problems sending it through a extra as a serializable. But when receiving it, i get the following error:
...
0
votes
4answers
48 views
Why is the print method printing empty data from Array index?
I posted a question yesterday regarding the sorting of indexes in an array. I was getting weird results, which were partly correct. I figured out the reason, but I don't know how to fix it.
I've ...
0
votes
3answers
75 views
Binary Search keeps returning -1?
This method is supposed to pass an array of objects:
Movie[] movieList = new Movie[6];
movieList[0] = new Drama("Titanic","James Cameron", 1997, 200.0, 80.0, 7.50);
movieList[1] = new ...
-2
votes
6answers
67 views
Removing duplicates from 2D array in java [on hold]
I have a 2D String array, something like
_________
|abc|123|
---------
|pqr|234|
---------
|mno|567|
---------
|abc|123|
---------
|abc|999|
What is the most efficient way to remove duplicate ...
0
votes
2answers
55 views
Getting a decimal to print with an array
I'm trying to get this "for" statement to print out a decimal value for an array, but I can't figure it out.
for ( int b = 2; b < totals.length; b++ )
{
int percent = totals[ b ] / ( 360000 ...
0
votes
2answers
27 views
Why is this putting the int value of the length in that index position and not just adding to it?
I am iterating over a file and getting the number of characters in each word. When I find the length of each word it is putting the int value of the amount of characters into that array index ...
0
votes
0answers
14 views
How to use FasterXML/jackson-databind to deserialize List<Map> as List
I spent some time googling try to figure out how to deserialize this json as a List<Link>. I know it's List<Map<String, Link>>. So I would like know if anyone knows if it's possible ...
0
votes
2answers
74 views
How to repeat until the user enters an integer?
This is currently my code.
What I want it to do, is accept up to 10 numbers in an array then do and display some math for them. What I managed to do, is catch errors, then stop the program.
What I ...
0
votes
3answers
64 views
Sorting double arrays into ascending order
I'm currently trying to sort a Double Array into ascending order manually. The problem I'm having is that the output only lists the 1st smallest value at the top (which is correct), but lists the rest ...
0
votes
4answers
60 views
Nested switch with different expression types: ArrayIndexOutOfBoundsException -4
I am herewith enclosing my code for your reference. while I am executing the below code for the multiplication functionality,i am getting the below error,
Exception in thread "main" ...
0
votes
4answers
98 views
Is it possible to have an array as the elements of an array?
Is it possible to have an array as the elements of an array?
For example in the first index it can have an array of size 3, and the second index it can have an array of size 40.
I want to know if you ...
0
votes
1answer
29 views
Put results of Android Wifi Scan into parsed array
I am trying to build a wireless location footprint system for the University I attend. Using the attached code I am able to view wireless access points and the various information associated with them ...
3
votes
5answers
95 views
String Array length is showing 1 even the array is empty after call split by comma (,) [duplicate]
Here is my code:
serialNumbers = "";
String[] serialArray = serialNumbers.split(",");
int arrayLength = serialArray.length;
arrayLength is showing 1 even there have no value in serialArray. I was ...
0
votes
5answers
123 views
Explain the code
Here is the code:
basically, this code prints out 52 cards with the suit + rank.
package javaapplication52;
public class JavaApplication52 {
public static void deck() {
String[] suit ...
0
votes
4answers
64 views
How to retrieve Array values in Java?
In my Java Application i'm getting Request parameter like Array
<script type="text/javascript">
var names = new Array();
$.ajax({
url : "Result",
type : 'POST',
...
3
votes
2answers
82 views
Clean way to initialize an arraylist
I want an Arraylist in Java, which I want to fill with 10's
ArrayList<Integer> list = new ArrayList<Integer>(100);
for (int i = 0; i < 100; i++) {
list.add(10);
}
I'm going to ...
0
votes
1answer
56 views
“Argument is not an array” exception when setting array value using Java reflection
I need to create an array at running time according to the values of the input array tableParameter.
An example of my code is as follows:
int[] tableParameter = new int[dimension + 1];
...
0
votes
1answer
44 views
Iterating an array from both ends using two indices
This is more of an self defined programming exercise than a real problem. I have an array of java.lang.Comparable items. I need to maintain two pointers (an index into the array i.e., int values) i,j ...
0
votes
1answer
38 views
Class.forName for array of custom objects
Suppose I have a class Point. When I do:
Class myClass = Class.forName("Point");
It works. But when I do:
Class myNewClass = Class.forName("[L" + "Point");
It does not work. What can be done to ...
-2
votes
5answers
94 views
print an array whose length and dimensions are unknown [on hold]
I was asked at an interview to print all the elements of an array whose length and dimensions are unknown. i could not find a way but the interviewer said that it can be done. can any one tell how it ...