I need to concatenate two String arrays in Java.
void f(String[] first, String[] second) {
String[] both = ???
}
What is the easiest way to do this?
|
Now that Java is open source, one of the first things I would like to do is to disable array bounds checking for certain blocks of code, where I'm dead sure ... |
I'm trying to display the contents of an ordered array in something like a JTextField.
for (int i=0; i<array.length; i++) {
this.textField.setText(array[i]);
}
This won't work for two reasons. The first ... |
I have a fairly expensive array calculation (SpectralResponse) which I like to keep to a minimum. I figured the best way is to store them and bring it back up when ... |
I have a 2D array of doubles in Java which is basically a table of values and I want to find out how many rows it has...
It is declared elsewhere (and ... |
I have a program I am writing that works on the principle of populating a two dimensional array to check the winning condition, it's noughts and crosses so the two dimensional ... |
I have put few elements in array (e.g. 5 elements)
The first element, index[0] of the array will automatically displayed without the user need to click the button.
After the button clicked, ... |
|
I'm trying to find a counterexample to the Pólya Conjecture which will be somewhere in the 900 millions. I'm using a very efficient algorithm that doesn't even require any ... |
Here is what I'm suppose to accomplish:
Write a program that stimulates a
bean machine Your program should
prompt the user to enter the number of
... |
I have an array, and need to find the index of the smallest item.
a = [2, 2, 2, 3, 3, 4, 3]
This should return 0.
Please note that the content and ordering ... |
I'm working on a Bruce Eckel exercise on how to take a keyboard command line input and put it into an array. It's supposed to take 3 separate inputs and place ... |
I'm currently trying to draw shapes with 2D Arrays. In my class there is a global array defined with public char canvas[][];
Up until now, I have only declared arrays with char ... |
I'm looking for a method in Java that will return a segment of an array. An example would be to get the byte array containing the 4th and 5th bytes of ... |
I have a bidimensional Object array in Java.
Some indices aren´t nor used, because thei were skipped during array fill.
Array looks like:
Array[0][0]
Array[0][1]
Array[0][2]
Array[1][0]
Array[1][1]
Array[1][2]
Array[3][0]
Array[3][1]
Array[3][2]
The 2 is missing, how can i rebuild the indices ... |
Hmmm. I have a table which is an array of structures I need to store in Java. The naive don't-worry-about-memory approach says do this:
public class Record {
final private int ...
|
with Java5 we can write:
Foo[] foos = ...
for (Foo foo : foos)
or just using an Iterable in the for loop. This is very handy.
However you can't write a generic method ... |
I'm looking for a java library or some help to write my own interpolation function. That is I have two arrays of doubles which are potentially different sizes, but are ... |
I would like to use constants for annotation values.
interface Client {
@Retention(RUNTIME)
@Target(METHOD)
@interface SomeAnnotation { String[] values(); }
...
|
Why does the first one work and the second not work?
1) OK
String[] foo = {"foo"};
bar.setArray(foo);
2) BAD
bar.setArray({"foo"});
Is there a quick way to create a String[] on a single line?
|
If you're not interested in a story, skip the first 2 paragraphs.
I was talking to a friend about arrays and why they (still) crash if you try to access an object ... |
In my class, I have a method that returns an array like this.
double arrValues[] = ClassX.getValues();
I wonder that, does the array size have any influence on performance. Are there any copy ... |
I have an array of type int
matrix[][]
and it has values of 0 and 1
000000000
101010111
000010100
110011001
the values are different to the above, however this is a random example.
What i need to do ... |
Hey, I was trying to combine several arrays of type double into one single array, what is the best way to do it? Thanks!
|
A super trivial beginner question on Java arrays:
Can anyone explain why the compiler doesn't like this:
class Cycle {}
public class CycleTest {
Cycle[] cy = new Cycle[3];
...
|
I was wondering if I could have some pseudo code for working out the following
i need to loop through a 2d array(the method i am working on takes an int). It ... |
Return an array that contains the exact same numbers as the given array, but rearranged so that all the zeros are grouped at the start of the array. The order of ... |
Assume I have an array of doubles that looks like the following:
Array[10] = {10, 10, 10, 3, 10, 10, 6, 10, 10, 9, 10}
I need a function that can determine what ... |
Sorry for the newbie question, I'm used to C# so my Java framework knowledge is not so good.
I have a couple of arrays:
int[] numbers = new int[10];
String[] names = new String[10];
//populate ...
|
I need an efficient Java structure to manipulate very sparse vectors of doubles: basic read / write operations. I implemented it in a HashMap but the access is too slow. Should ... |
I have an algorithm which currently allocates a very large array of doubles, which it updates and searches frequently. The size of the array is N^2/2, where N is the ... |
A follow up to my Item Scanner, a java tool that scans through a directory of *.txt files.
Thank you all for the help! However now I have a different problem.
When I ... |
While using method Arrays.deepToString(Object [] a) I am facing this problem which I can put down in this way.
Object [] not_allowed = new int[]{7, 9, 8};
Object [] allowed ...
|
Can you help me out with this question please.
Question:
Given the following array declarations
double readings[];
String urls[];
TicketMachine[] machines;
write assignments that accomplish the following tasks:
- make the
readings variable refer to an array that ... |
i'm starting with Java and i'm learning about setters,getters and encapsulation.
I have a very simple program, 2 classes:
- Container has a private int array
(numArray) with his setter & getter.
- Main creates a Container ...
|
private final String[] okFileExtensions = new String[] {"csv"};
Would someone please explain why {} is written after a String array decleration?
Thanks.
|
From looking at the Java Collections API i see that arrays are not regarded as collections.
If not what are arrays regarded as?
|
Well I wrote some code and all I was doing was for loops, but changing which method I called. I tried using a for loop so it'd be a bit neater ... |
Arrays are implemented as objects in java right? If so, where could I look at the source code for the array class. I am wondering if the length variable in arrays ... |
I'm trying to build an array of prime numbers in Java.
if(c % 2 != 0 || c % 3 != 0 || c % 5 != 0) {
...
|
Is there a syntax for declaring anonymous arrays in BeanShell? I would like to write code analogous to the following:
print(Arrays.asList("cat", "dog"))
but BeanShell fails to find the "asList" method, presumably because ... |
I am new bie to java unable to check for null.
can you enlighten me on this.
I have int array which has no elements
I tried this code
int[] k = new int[3];
if(k==null)
{
...
|
I want to store the array returned by a method into another array. How can I do this?
public int[] method()
{
int z[] = {1,2,3,5};
return z;
}
When I call this method, how ... |
In the code below, the nodes of a postorder tree traversal is always printed
I m wondering if there is a way to store these nodes in the postorder sequence in an ... |
Im am currently developing an automated "test" class (running several individual tests on other classes in the same package). The aim of the test file is to show whether each test ... |
The following code snippet attempts to create a Tib DaemonManager connecting to a particular rvd, and then query for that rvd's services.
public static void main(String[] args) throws RuntimeException {
...
|
We are working on a lab assignment for my CS&E class and I think I can ask this question without going into detail of the entire lab requirements, but is it ... |
Could any one please tell me the meaning of "++" with array in the following code in Java:
int [ ] arr = new int[ 4 ];
...
|
How do you create, say, 30 arrays (it doesn't matter of what type, say, char[])? It seems to me that it is not a good idea, to create them one by ... |
How can I store arrays in single array?
e.g. I have four different arrays, I want to store it in single array int storeAllArray [] and when I call e.g. storeAllArray[1] ... |
i currently have a method that checks what is around the centre item in a 3x3 grid, if what is in the 8 adjacent positions is containing what i am checking ... |
Is there a implemented Java method in jdk to do this?
public static Byte[] box(byte[] byteArray) {
Byte[] box = new Byte[byteArray.length];
for (int i = 0; i < box.length; i++) {
...
|
how to take user input in Array using Java?
i.e we are not initializing it by ourself in our program but the user is going to give its value..
please guide!!
|
We are hosting an application on SUN JVM that handles a lot of XML parsing using Jaxb.
The application is parsing the XML fine using JRockit 5 but when using the SUN ... |
I have a 3-multidimentional array :
int[][][] env;
which i would like to initialize with data in a text file. The data in the text file looks like this:
{ ...
|
I have some String[] arrays, for example:
['a1', 'a2']
['b1', 'b2', 'b3', 'b4']
['c1']
How can I mix them, so that I get ['a1', 'b1', 'c1', 'a2', 'b2', 'b3', 'b4'] (0 element of a, then ... |
I'm a beginner in java. I want the logic of the small program.
I have two arrays
array = {a1,a2,a3,a4,a5,,,,,,,,,an}
and
array2 = {b1,b2,b3,b4,,,,,,,,,,,bn}
I want string as a1b1,a2a3b2b3,a4a5a6b4b5b6,.... so on up to n
Please tell ... |
I have an array called Names[5] and one called scores[5][5].
Each row corresponds with the name in the respective index.
I need to find the highest score in the scores array and return ... |
Okay, here is what I want to do:
I want to implement a crossover method for arrays.
It is supposed to take 2 arrays of same size and return two new arrays that ... |
I have an assignment of making a blackjack like program in a class. My first problem I am dealing with is creating an array of the cards. The professor wants an ... |
Is it possible to have an array that contains two different types of data? I want to have an array that contains a double and also a string. I attempted:
ArrayList<double><String> array;
But ... |
Effective java says:
// Potential security hole!
static public final Thing[] VALUES = { ... };
Can somebody tell me what is the security hole?
|
I've just started studying and I need help on one of my exercises.
I need the end user to input a rain fall number for each month.
I then need to ... |
Note: This is an assignment.
Hi,
Continuing with my Set implementation using Java basic array, I'm now struggling with the 3 to last function namely the union.
import java.io.*;
class Set {
...
|
OK so, is there an efficient way to detect on what array you're currently on by using the KeyListener?
My code: http://www.javadan.pastebin.com/X68VyuGL
What I am trying to do here is ... |
I know I was just asking a question earlier facepalm
This is in Java coding by the way.
Well after everyones VERY VERY helpful advice (thank you guys alot)
I managed to get over ... |
I need to write a program where the program would generate random letter and i would need to store this random character into an array
...
|
I've been told that
int[] numbers
and
int numbers[]
are equivalent. I've only ever seen the former though. What impetus is there, if ever, to write the latter?
|
How do you:
1. Initialize (create) an Array.
2. Push a String value into it.
3. Push another String value into it.
4. Dump it to get its contents.
|
I have a Java bean ala
@XmlRootElement public class Bean {
@XmlElementWrapper(name = "ints") @XmlElement(name = "int")
int[] values;
// constructors, getters, setters, ...
|
Please help me understand the following:
I create a CharBuffer using
CharBuffer.wrapped(new char[12], 2, 10) (array, offset, length)
so I would expect that the array is accessed with an offset of 2 and total ... |
I'm trying to code a method which loads a map according from a number inside loadBoard(NUMBER_HERE); But I get 'unreachable statment' on the line
return board;
Here is my code:
public int[][] loadBoard(int ...
|
OK let's say I have this array:
public int[][] loadBoard(int map) {
if (map == 1) { return new int[][] {
{2,2,24,24,24,24,24,1,3,0,0,0,1 }, {
2,2,24,23,23,23,24,1,3,0,0,0,1 }, {
1,1,24,23,23,23,24,1,3,3,3,3,1 ...
|
im trying make one replace in string from a array but this dont work
dna[i].replace('T', 'C');
and with this way work?
"ATCTA".replace('T', 'C');
why dont work with array, how i can use use a replace ... |
I am calling a JavaScript function using the rhino API:
Function fct = context.compileFunction(scope, script, "script", 1, null);
Scriptable result = (Scriptable) fct.call(
...
|
I have a method like the following:
public void launch(String cmd, String [] args, String workingDir)
Inside this method I call ProcessBuilder.
How can I call ProcessBuilder including an arbitrary ... |
I'm trying to add functionality to the Arrays-class. In my project I use the (static) methods from Arrays and have some other methods that also handle array-conversion, sorting, etc...
I'm trying to ... |
I would like to divide a large byte array into smaller chunks (say 64 bytes). Please help me with this.
|
for(int m=0; m< checkBoxValue.length ; m++)
{
System.out.println("check box in model class"+checkBoxValue[m]+"\n");
}
This loop is to print two values in array. It prints the values But after ... |
Why is it that this works:
int[] array = {1, 2, 3};
but this doesn't:
int[] array;
array = {1, 2, 3};
If I have an array instance variable and I want to initialize it in ... |
Simply put. Why did this make my code malfunction after awhile.
//Color[][] colorArr = new Color[Width][Height]();
private void shiftRowsDown(int row) {
for (int i = row; i > 0; i--)
...
|
What is the "easiest" way for you to create a singleton (with exactly one element) Objects array in Java ?
|
I'm trying to use double-checked locking to maintain an array of binomial coefficients, but I read recently that double-checked locking doesn't work. Efficiency is extremely important so using volatile isn't ... |
I am new to programming and Java and trying to write a program which takes two arrays as input and reports back their sum. I want to do this by creating ... |
I have created an Ant task, wherein i would like to have an property array? First of all, is it possible? Does ant allows us to have a property array?
public class ...
|
Is there an immutable alternative to the primitive arrays in Java? Making a primitive array final doesn't actually prevent one from doing something like
final int[] array = new int[] {0, 1, ...
|
If I have class A { and class B extends A { will
B[] b = new B[1];
b[0] = new B();
System.out.println(b instanceof A[]);
print out true or false?
|
final Integer[] arr={1,2,3};
arr[0]=3;
System.out.println(Arrays.toString(arr));
I tried the above code to see whether a final array's variables can be reassigned[ ans:it can be].I understand that by a final Integer[] array it means we cannot assign ... |
Take this example:
public class foo
{
public int[] func()
{
int arr[] = new int[3];
...
|
This is just a simple question, and I can't find the answer in the documentation !
String args[] = new String[0];
args[0] = "test";
Is that correct ? Does this creates an array with ... |
public class Main {
public static void main(String[] args) {
int[] x = {1, 2, 3};
increase(x);
...
|
I'm trying to output a square of X's using an array. The diagonals of the square will be filled with 'X' and the empties will be filled with spaces '_'.
Here's ... |
I'm trying to create a triangle where empty cells have spaces and non empty cells have X's.
public static char[][] Triangle(int size) {
...
|
I'm working on a little server app with Java. So, I'm getting informations from different client, and if information comes in, the following method is called:
public void writeToArray(String data) {
...
|
package javaapplication1;
import java.io.*;
public class Main {
/**
...
|
I am working on an application which has a large array containing lines of numbers,
transNum[20000][200]//this is the 2d array containing the numbers and always keep track of the line numbers
I am ... |
I would like to know what are the weaknesses of the arrays. I think that it is very helpful to know in order to determine whether the arrays are the best ... |
I have a 3x4 array that I want to rotate left once, so that it becomes a 4x3. Imagine a box of values, and just rotate that box left. Here's the ... |
Lets say I have an int[][] arrayA and an int[][] arrayB. At any given coordinate in this array lies an RGB value. What I want to do is merge the RGB ... |
I have a function named resize, which takes a source array, and resizes to new widths and height. The method I'm using, I think, is inefficient. I heard there's a better ... |
is there anyone that can help me with java program I spent hour troubleshooting?
I have no problem reading the file into a string array but I don't seem to know ... |