Tagged Questions
0
votes
5answers
29 views
How to create generic primitive arrays?
This is a following question coming from Two methods for creating generic arrays.
With given two methods,
@SuppressWarnings("unchecked")
static <T> T[] array1(final Class<T> elementType, ...
0
votes
2answers
53 views
Combining array indexes
I have created two arrays. One to store names and one to store sales. I am trying to link the indexes of each together so that index 1 from then name array will bring up the value of index 1 of the ...
-4
votes
3answers
55 views
Accessing array at index 0 returnes correctly, but accessing at index 1+ generates error? [closed]
Here is the code:
System.out.println("[Server] Handshake Recieved");
String fdata = new String(p.getData());
String[] data = fdata.split(";");
System.out.println(fdata);
...
4
votes
4answers
58 views
How can I treat an underlying byte array as an array of shorts? Or ints? Or longs?
I am an embedded engineer, working in Java. I need to communicate with devices, and frequently I need to massage buffers into the form needed by or produced by some hardware.
I have spent ...
-1
votes
3answers
50 views
Java program using arrays, finding max int? [closed]
The Game class contains a main method that:
(10 points) Checks to see if any names have been specified on the command line. If no names are specified, the method prints the message “No names ...
-2
votes
3answers
42 views
Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: 100
I am building a project in java (with Netbeans) which is about classes. So i have this
import javax.swing.*;
public class TestHumanResourcesTEI {
public static void main(String[] args) {
final ...
-6
votes
3answers
63 views
Java array, append object items to array [closed]
If anyone could help me with the following I would be very appreciative.
The Rack class represents the set of tiles that belong to a player. The Rack class must:
(2 points) Include a private ...
0
votes
0answers
21 views
Assistance with Circular Extended Array Deque
I'm trying to implement a Deque utilizing a circular array that extends when the array gets full. However, I am getting an IndexOutOfBoundsException. I think my issue is with the insertLast method. ...
-1
votes
3answers
59 views
How can I see if part of a word is contained in an array? [closed]
For instance, let's say I have the following array of app names:
{"Math Workshop", "Math Place", "Mathematics", "Angry Birds"}
I want to scan this array for any elements that contains the word ...
0
votes
2answers
34 views
Array initalization using reflection
Someone please help to understand how can we initialize array in java using reflection.
for a simple object we can do like this :
Class l_dto_class = Class.forName(p_fld.getType().getName());
Object ...
-2
votes
3answers
104 views
Why values are not the same?
I have the following piece of code:
public int[][][] arrMethod1(){
for (int idx=0;idx< x;idx++ ){
arr[idx]=arrMethod2();
System.out.println("arr "+idx+" is ...
0
votes
1answer
60 views
Find count of duplicate elements and create arrays of them
i have a list of elements in array like [121,122,121,122,123,121,122]
output should be arrays of all the duplicate elements like
[121,121,121]
[122,122,122]
[123]
I am limited to use Java 1.4. ...
4
votes
3answers
83 views
Two methods for creating generic arrays
I've learned following two methods for creating generic arrays.
One is
@SuppressWarnings("unchecked")
static <T> T[] array1(final Class<T> elementType, final int size) {
return ...
1
vote
1answer
23 views
JFreeChart Bar Chart Production
I'm trying to create a bar chart that generates a dataset from within a for loop.
String scores = scoreText.getText();
String[] data = scores.split(",");
DefaultCategoryDataset barChartDataset = ...
-1
votes
2answers
43 views
Find TOP 10 words from text: 95%-working code [closed]
I start learn Java few month ago. For my homework I write this code - to find TOP 10 words from text file. For me it very interesting task. And hard. The third day I can't finish this software - I ...
0
votes
1answer
40 views
How can I get an element type class from an array type class?
Can I get Class<T> from Class<T[]>?
public static <T> void doSometing(final Class<T[]> arrayType) {
final Class<T> elementType; // = @@?
}
Or, can I get ...
0
votes
1answer
65 views
Array of objects within array of objects
I'm fairly new to Java and I'm having a bit of trouble completing an assignment.
We are asked to create a program that takes information from companies (we are supposed to create at least three). ...
1
vote
1answer
63 views
JDK's Arrays vs. Guava's ImmutableList
Is there advanteges between using one-line list creation with com.google.common.collect.ImmutableList.of(...) and java.util.Arrays.asList(...) ?
1
vote
0answers
63 views
Print to file produces unwanted text
I have something like this:
private void myPrinter(int[] arr) throws IOException{
FileWriter outFile = new FileWriter("myFile.txt",true);
PrintWriter out = new PrintWriter(outFile);
...
0
votes
4answers
69 views
Index out of bounds exception error
I have the following code which appears to generate an array error on the following bit:
int run = 0;
while(myNet.RunNet(q) > 0.2 && run < 1000) {
...
1
vote
1answer
27 views
Formatting an array element
Here's the scenario. User enters 3 types of inputs:
1/1/2013 12:00:00 AM_5/31/2013 12:00:00 AM
1/1/2013 12:00:00 AM_
_5/31/2013 12:00:00 AM
The input is for date range query.
1st input: Split by ...
0
votes
5answers
40 views
Parsing an Extra String to Check For Data
I have an extra which will be passed to my service as an extra and I need to check to see if it contains specific data but I'm not sure exactly how this is accomplished so I could use a hand in ...
1
vote
1answer
22 views
Simple ViewPager - Single Layout
I'm trying to do a simple ViewPager from an array of images.
My array is:
<string-array name="ot_images">
<item>"file:///android_res/drawable/ot_100.jpg"</item>
...
-1
votes
3answers
53 views
Index out of bounds in for statement [closed]
I am getting an error during runtime: "index array out of bounds", i cannot find where though. The program is suppose to take 25 random numbers, separate them into even and odd numbers and display the ...
0
votes
2answers
63 views
Comparing arrays in java?
import java.io.File;
import java.util.Scanner;
public class scoresedit {
public static void main(String[] args) throws Exception{
System.out.println("Reads in a file at the beginning of a loop, ...
1
vote
0answers
21 views
Android Bluetooth Java, Constant bluetooth stream to fill up array and write to sdcard
I am writing an Android app that uses bluetooth to stream data (bytes) into an array in another class. The idea behind this is to record a set amount of data (i.e. buffer[60000]) and when it is full, ...
0
votes
6answers
78 views
Printing numbers in array
Im trying to write a function to display all combinations in a jagged array, where each combination contains one element from each sub-array. The jagged array can consist of any number of arrays and ...
0
votes
5answers
92 views
Instantiating different class in constructor in Java
I am very new to Java have just started working on simple example programs.
How can I create class A's instance inside class B's constructor. For example, I want to create an array of objects of ...
0
votes
2answers
77 views
still having error for NullPointerException [duplicate]
i tried to tweak here and here but still come out error.
the error is when i want to do something with the element inside the array either want to display it, store element or
searching using index. ...
-1
votes
1answer
67 views
Algorithm for matching hospitals with students based on their preferences? [closed]
I have this problem in which given a set of hospital preferences and a set of student preferences, the software should return a list of matches satisfying the following conditions:
If a hospital and ...