Tagged Questions
-3
votes
6answers
48 views
Java - how to return a null in this String method?
How to make this string return a null if we put things = null
public class Test {
static String concatAll(Object[] things) {
StringBuffer result = new StringBuffer();
for (int i = 0; i < ...
0
votes
0answers
38 views
Android: compare string input (edittext) with arraylist
I want to compare my input string with an array list of another class, so I used the searchfield to compare them. As below it works fine.
Input Class
public class Suche extends Activity{
private ...
0
votes
4answers
82 views
Java - I can't replace char 'Á' with another char in String
Why this "Á" alphabet doesn't change? this code works on the other alphabet but Á.
public class Convert {
static String turkishCharacterConverter(String s) {
StringBuilder x = new ...
0
votes
2answers
75 views
setting two arrays equal to each other in java
I am writing a program that has a double array called data.
My code so far is the following.
public class DataSet {
private double[] data;
private int dataSize;
public DataSet(){
dataSize = 0;
...
0
votes
0answers
55 views
Assignment Java: arrays methods pointers constructors
I need some help with my assignment with Java because i basically don't understand a thing about the language and still learning it on school but either my teachers are explaining it really badly or ...
0
votes
0answers
23 views
How to get array data in Java from socket.io server?
I'm emitting this event and data from Node.js server through socket.io:
socket.emit('users', { users: ["353426056115918","868438010686650","358968048675819"] });
I can get this event in Java ...
0
votes
1answer
24 views
Decimal to Binary Format Conversion
I have to write a Java program as part of an assignment to convert decimal inputs to the following formats: unsigned binary, unsigned hex, signed-magnitude, 1’s complement and 2’s complement. The ...
1
vote
5answers
66 views
Find an integer in an Array in a short manner in Java
I already tried this post:
Java, Simplified check if int array contains int
and tried this
int[] temp = {3,9,15,21,27,33,39};
HashSet<Integer> otherBy3 = new ...
0
votes
6answers
47 views
Performance of copying/merging arrays in Java
I need to merge two double matrices in Java and I am aware of
public static double[] copyOf(double[] original, int newLength)which is defined in the class java.util.Array
But I am concerned about ...
2
votes
4answers
41 views
Instantiate a map in a more concise manner in Java [duplicate]
Is there any shorter way of doing this?
Map<String, Integer> values = new HashMap<String, Integer>();
values.put("A", 1);
values.put("E", 1);
values.put("D", 2);
values.put("R", 2);
...
-4
votes
1answer
57 views
Split string using a string, split() function
I have the string
"Hello\nIm\nCory!"
How can I separate the string into String[] aLore?
I have used string.split()
using:
"\n", "\\n", "\\\n", "\\\\n"
All of those with plus' at the end, all ...
-2
votes
0answers
46 views
Values and Frequencies Array? [on hold]
I was hoping I could find some help on a problem from my Computer Science course. Here it is:
"Write a program that creates an array of 11 integers using an initializer list. Call the array nums.
...
1
vote
3answers
42 views
How to create a fixed size array of a generic type in Java?
I have this code which gives me the error that "Cannot create a generic array of
BST_Node"
BST_Node<Integer>[] arrayTree = new BST_Node<Integer>[treeSize];
I don't know why ...
-4
votes
2answers
44 views
How do I match a string to a user input using an if statement? (Java) [duplicate]
while (x == 1)
{
String[] riddles = new String[5] ;
riddles[0] = ("Hellowrite1") ;
riddles[1] = ("write2") ;
riddles[2] = ("write3") ;
riddles[3] = ...
0
votes
4answers
32 views
elements not being written into array in java
So I've written a programme used to solve a concrete equation having been given one parameter int n. The code I have is:
static double getSolution1(int n)
{
double [] a = new double[n+1];
...
0
votes
1answer
41 views
Codility equilibrium index sample test - my stab at it
I am doing the following Codility Test to hone my skills, or lack of them.
This is a demo task. You can read about this task and its solutions in this blog post.
A zero-indexed array A consisting of ...
0
votes
1answer
24 views
java BufferedImage to int[] issue
I have a BufferedImage (Type.TYPE_INT_ARGB) that I want to convert to a int[]. I do this by using the following method:
((DataBufferInt)src.getRaster().getDataBuffer()).getData();. But when I do this ...
0
votes
2answers
49 views
Create an array where every value is an enum?
I am trying to create a deck of cards That I am going to be choosing from to make a map. I have 16 cards, that are of two different types.
I first have my class with an enum :
package Game;
public ...
1
vote
1answer
33 views
Scanning and modifying 2D Arrays
I am having some trouble with a method that needs to search a final static array that contains information about seating prices (simple school project).
The array of seat prices is as follows (called ...
0
votes
2answers
43 views
(ADDED) Noughts and Crosses game. While loop
for(int i = 0; i < 3; i++){
for(int j = 0; j < 3; j++){
visBoard[i][j] = "[ ]";
board[i][j] = 0;
check[i][j] = false;
...
3
votes
1answer
62 views
Match a regular expression against an array
We all know how we can use regular expressions to find things in strings. However, regular expressions are not, at least mathematically, limited to just actual Strings and char[]s; one could use a ...
1
vote
3answers
52 views
Array initialization and the “new” keyword
Syntax aside, is there any difference between the following two statements?
String[] str = { "test" };
and
String[] str = new String[] {"test"};
2
votes
1answer
66 views
Array Casting Issue
I have the following code:
String []d=new String[]{"y","z"};
Object []ab=d;
d=(String[]) ab;
System.out.println(d[0]);
System.out.println(ab[0]);
as expected returns y twice
But the following code ...
-1
votes
5answers
87 views
In Java, how can I test if an Array contains the same value?
I´m looking for an method to detect if all objects from a array(list) same.
e. g.
arraylist1 = {"1", "1", "1", "1"} = true
arraylist2 = {"1", "1", "0", "1"} = false
Thanks for help
0
votes
1answer
18 views
How to input a file via Unix input redirection into my java programm as an array?
I'm a beginner in Java and need some help with this problem. First of all let me show you my actual program.
import java.util.Scanner;
import java.util.Arrays;
public class IntArraySort {
...
0
votes
3answers
44 views
How do I fix an arrayindexoutofboundsexception error?
this is the code I am dealing with
public class NameTag
{
public static void main (String[] args)
{
System.out.println ();
System.out.println (" " + args[0]);
...
-1
votes
1answer
21 views
Converting native int to Jbyte Array
I have a JNI C++ function in which i want to convert a integer to jbyte array. I need to first put it in a native integer to make sure that to other side (a C++ client can read it)
The funciton looks ...
-1
votes
2answers
26 views
Reading file into 2D array with unknown dimensions - Java
The task at hand is to read in a file with unspecified dimensions... The only stipulation I have with completing this task is that I'm only allowed to use Arrays - no arraylists, lists, maps, trees, ...
0
votes
7answers
77 views
Java program to calculate the number of times each character appears in a string [duplicate]
I typed out this program to count the number of times each character appears in a String.
import java.util.Scanner;
public class fre {
public static void main(String[] args) {
Scanner s=new ...
0
votes
1answer
36 views
How to create an array with a random amount of values
I need to create an array that has a random amount of values from 8 to 12, but it says my variable is incompatible. What do I have to change? Should x not be an int?
Here is the first part of the ...
0
votes
2answers
55 views
Multiplication of an array by one and other not working
First of all: I'm a beginner in programming and working on an assignment for school. A schoolmate and I are working on an application for a teacher, who has a site about physics.
We want to ...
0
votes
1answer
70 views
Java: Implementation of Interfaces and abstact classes
I am trying to build a program where I have a visual representation of an int array while they get sorted. There will be two different search algorithms of choice. All the functionality is split up ...
0
votes
0answers
37 views
How to convert Vector to JSON array in Java?
I want to pass a vector from a java class to a JSON array. Because I'm passing it to localStorage it's supposed to appear as a string.
"[thisisastring,thisisalsoastring,morestrings,onelaststring]"
...
0
votes
9answers
63 views
Finding the maximum number in the array recursively
I'm trying to understand recursion by doing some codes. This code should find the maximum number in the array recursively, but for some reason it doesn't work.
Thanks for your help!
public static ...
0
votes
4answers
41 views
Converting ResultSet to array of to int
I am trying to convert ResultSet to array of int, that because the method I have returns int[]:
public static int[] GetPathIDsFromDB (String Dbnum, int objectid) throws SQLException{
String ...
0
votes
2answers
47 views
Is it possible to assign an array to a two-dimensional array?
I am making an expense tracker program for an assessment project, but the thing is, the question sheet is too vague. One of the problems is that, I am not sure if I should just stick to a ...
-1
votes
1answer
49 views
Java decimal bigger than BigDecimal?
Here is the problem I am having. I have a CSV file I am reading with 4381 small decimal numbers mostly between -5 and 5. Examples of them are 0.00000822, -0.20929117, -2.204, 4.88490078.
In my ...
-1
votes
3answers
56 views
Finding K Highest Sums from multiple integer lists [on hold]
Given several lists/array of integers ..need to find out the K highest sums picking only one element from each list.Each list/array contains integers in a non-increasing sequence.
For example, given ...
1
vote
2answers
56 views
Shifting an object in an Array list left or right Randomly
I am working on some practice on an Array problem in Java. I know that when you declare an object, you can put it in an array an move right or left. However, is there anyway that you can move it ...
0
votes
4answers
50 views
Finding multiple modes in an array of integers with 1000 elements
So I need a way to find the mode(s) in an array of 1000 elements, with each element generated randomly using math.Random() from 0-300.
int[] nums = new int[1000];
for(int counter = 0; counter ...
-2
votes
2answers
48 views
How to convert a String[] into a set?
I did this:
Set<String> mySet = new TreeSet<String>();
String list = ("word,another,word2"); // actually this is much bigger
String[] wordArr = list.split(",");
mySet.addAll(wordArr);
...
0
votes
4answers
72 views
How can I make my java program output properly?
I need help to make my program output properly. The program is suppose to start at 1985 and end at 2025. In 1985 it should be 100%. After each year it should go down by 0.45%. If the person enter in ...
0
votes
4answers
60 views
Array copy exclude each x element
I am converting an RGBA image to RGB. Using naive array copy:
for (int j=0, i=0; i<argbBytes.length; i++){
if (i%4 < 3) {
thumbRGB888[j++] = argbBytes[i];
}
}
But, as ...
1
vote
2answers
75 views
Class that returns arrays
Im very very new to java. Im trying to make a class that returns some info about a few movies (all this info is stored in array). Im stuck and dont know what to do. Here is my code
Movies class:
...
-1
votes
1answer
54 views
Null pointer exception
I am trying to display the elements of my ArrayList in an action listener method by calling a printlibrary method from another class(library). I keep getting a null pointer exception at this line ...
0
votes
3answers
72 views
How to find the smallest and the biggest number of items in array in Java?
I was wondering if there is any method to display the highest and the smallest number of items stored in array/linkedlist.
public Checkout()
{
tillQueue = new LinkedList<String>();
...
0
votes
2answers
53 views
Store only numbers on an array
I have a class Cliente that has an ArrayList which stores the classes Jamon, Cereal, etc in it. This classes (Jamon, Cereal, etc) are extened from a superclass called Producto.
What I need is an ...
1
vote
6answers
78 views
Generate an array of random integers with non-uniform distribution
I want to write Java code to produce an array of random integers in the range [1,4]. The array's length is N, which is provided at run time. The problem is that the range [1,4] is not uniformly ...
0
votes
0answers
45 views
Use arraylist info in javascript
I have a web service client which returns an object arraylist and two other values, this is the class that the web-service returns:
public class RespuestaObtenerLimites {
private int cdgError;
...
1
vote
0answers
16 views
Jackson: deserialization of Object Array having different Type Items
Jackson: Deserlization of Object Array having different Type Items
I am converting an object array to json, that works fine. But when I try to get object array back from json, some items loose their ...