class 1 « array « Java Collection Q&A

Java Collection Q&A
3.Array Byte
4.Array Char
5.Array Convert
6.Array Dimension
7.Array Integer
8.Array Object
9.Array String
14.Garbage Collection
Java Collection Q&A » array » class 1 

1. How to send array files to other class

How can i send a files which stored in array to other class? I have tried this code but isnt working.

public class abc {
    String ...

2. how do i build an array in the test class

public static void main(String[] args){
  Employee [] employeeList =
    // build your list here
how exactly do I build my ...

3. Java Templates array of Template Type in Template

I would like to implement a template which contains an array of the template Type. Is there a way to do something similar to what I have outlined in my sample ...

4. Class Method with arguments that returns an array

I'm pretty new to Java and not from a programming background. I am doing a course and am stuck on a piece I hope this is appropriate to ask a ...

5. Try-Catch-Throw in the same Java class

Is it possible to catch a method in the current class the try-catch block is running on? for example:

  public static void arrayOutOfBoundsException(){
      System.out.println("Array out ...

6. Beginning Java (Working with Arrays; Class Assignment)

I am to the point where I feel as if I correctly wrote the code for this homework assignment. We were given a skeleton and 2 classes that we had to ...

7. Calling arrays from other methods in a different class

I need help dealing with an array in my java program. in my first class, "test", I set 4 variables and then send them to my other class (test2). arr[i] = ...

8. How does array class work in Java?

In Java, array is a class and extends Object. I am curious to know about this special array class. I don't find the class definition anywhere. Doing a getClass().getName() gives strange ...

9. Java template class that takes an array; any way to enforce that?

I'm writing a template class which should take an array as its type.

public class Foo<T> {...}
How best can I enforce that "T" is an array type? (int[], Bar[], ...) Preferably compile ...

10. Approach: Java array having instances of two different classes

I am trying to create a simple regex kind of thing for my own use where a character in a string can either be an exact match or one in among ...

11. Array vs Private class for internal representation: Java Ethics

I recently had a homework question where we were supposed to work with a chess board, and place a number of queens on the board. The question was trivial in terms ...

12. Obtaining the array Class of a component type

If I have an instance of Class, is there a way of obtaining a Class instance for its array type? What I'm essentially asking for is the equivalent of a method ...

13. Add custom array subscript accessor to class in Java?

In Python, you can add list subscripts to be accessors to data structures for custom classes:

class customFile:
def __getitem__(self,x):
    return self.list[x]

to get the behavior of:
newFile = customFile()
newFile.list[1] = 4
# ...

14. Using arrays in a class

Why can I do:

public class ThisTest {
    int[] anArray  = new int[10];             

15. Problem with an array of a Class which I created in Java

I want to create an array of a type which I create. Here's my problem:

public class MyFile
     int ...

16. Java I have an Array that cannot be resolved across a class

I have an Array that is in a class called MusicArray and I want to be able to print its data and search it in my SearchClass class

import java.util.Arrays;
import java.util.Scanner;

public class ...

17. Retrieving array class name

I have I problem. In a method I receive a general Object as parameter and I have to retrieve the name of the class

public void myMethod(Object o)
  String className = o.getClass().getName();

18. Calling a method from outside a class in Java

This seems to be a common question on here but for all the ones I read, they seem to deal with different things. I'm writing a program with a main class that ...

19. Java - Array of Inner Classes inside of Outer Class

Let's say I have:

public class A {
  public A() {

  public class B {
    public B() {

20. instantiating a class from array of interfaces

SEE THE EDIT HALFWAY DOWN THE POST. I'm new to java and all the formal declarations of inheritance are getting me a little confused. I have a interface like so:

public interface A{

21. Java: How to make into a class instead of the main?

So i have the following code:
and in my text file it says:

I'm able to read the file from my code below, but I want ...

22. creating an array in a class

I have a compilation problem in a Java program:

class FigureEditor {
   int[] a;             ----- Syntax error on ...

23. How to get this array "itemlist" from another class?

I want to pass the array from the class LoadInventory to the main class. How do I do it? Here is a loadInventory class where the item is read from a file ...

24. Why do I keep getting .class expected here? None of the usual problems are the culprit

In all the other cases I could find, it was due to code not in a method or incorrect bracketing, however I have checked all these. My code is this;

import java.util.*; ...

25. Multiple classes, arrays, static, non-static issues

P: 5 Jimmysevens Hi there, I'm new to java and would appreciate help with this. My project involves me creating 5 classes; Person, Employee, Demonstrator, Payroll and Test. Employee and demonstrator ...

27. display array stored from another class.

red moon hi! i'm taking my first java course. and i'm stuck in this one question. i've tried soo many ways but i still dont know how to do.. Question: 1. ...

29. Possible to make a class that acts like an Array? (like C#)

I remember in C#, you can do something (can't remember exactly) that will make your own class act just like it's an Array - you could forexample make a Book class and then a static class called Books and then just say Books[3] to access the fourth Book in Books. Is there a way to do that in Java?

30. Array class?

31. Class of array?

I have found a list of the letters in a book (Lemay and Cadenhead, teach yourself Java2 in 21 days, SAMS, 2/e, page 479). B byte C char D double F float I int J long L object S short Z boolean As you have seen from the link I gave earlier, there is an associated [ and [L is followed ...

32. Wrapper Classes for Arrays

Not sure exactly what your problem is. Are you trying to put the contents of the int array into an Integer array? If so, each element of the int array will need to be put into an Integer. int[] a = {1,2,3,4}; Integer[] b = new Integer[a.length]; for (int i = 0; i < a.length; i++) { b[i] = new Integer(a[i]); ...

33. acceessing an array from another class

Hi all I am having a little problem. I have a class called Student in that class there is a variable: public final static char[] GRADES = {'A', 'B', 'C', 'D', 'F'}; I have another class called GradePoint Inside of that class I have a method: public boolean validateGrades(char tempGrade)throws Exception { boolean valid = false; for(int i = 0; i ...

34. Arrays: Calling input from other methods and classes

I have a line of code within a method called storeStudent in a class called storage. students [hash] = Student.upperCase(name); The error message I am getting is: C:\java>javac incompatible types found : java.lang.String required: Student students [hash] = Student.upperCase(Student.studentName); ^ The line of code in the method called storeStudent in a class called storage is: public static int storeStudent ...

35. Best class to implement extensible arrays

Hi, I'm new to Java, coming over from years of SAP ABAP coding. I can see that arrays have to be declared as fixed at construction time. What if I want to extend the size of the array at run time? What are generally accepted classes to use for such operations? (I assume that there are some). I would like to ...

36. where is array class?

37. Solved: Reading from an array in another class file

I have an array in, den is suppose to collect data and put inside the array in den I need to read from the array to see wad has entered. If i use "a ent = new a;" I would get a blank array how do i read from to see what has ...

38. class name of java arrays

39. How should I return an array of a class type?

I'm trying to create a method 'GetPlayers' that returns an array of Class 'Player' inside the Class itself - Good idea or bad idea? If good, how would I use the method to create an instance of the array? e.g. Player players = new Player.GetPlayers(); (yes it's still early days for me :rolleyes Many thanks Paul. public class Player { private ...

40. abstract class yet again into arrays..

: //abstract class: public abstract class Account { private int acctNumber; private int accBalance; public Account () { accBalance = 0; } public Account (int acctNumber, int accBalance) { setAcctNumber(acctNumber); setAccBalance(accBalance); } public int getAcctNumber () { return acctNumber; } public void setAcctNumber (int acctNumber) { if (acctNumber > 0 ) { this.acctNumber = acctNumber; } } public int getAccBalance () ...

41. How get "base class" of an array?

If I have a method that takes an Object and the object can be an array (say Integer[][]), how would I find out that the base class is Integer? Doing a getClass() returns the Integer[][] class not Integer class. So I can't just use ".equals()" to see or even instanceof. how do I find the array's base class? For example: public ...

42. What King of Class is a Array?

43. Arrays class

44. Add instance of class into array

45. Which class represents array in java?

46. Using global arrays in inner classes

i was converting some C++ code to Java and was wondering how i get all of the methods to 'see' the global array? my solution i came up was to wrap all of the methods in an inner class, but before i go ahead and implement it i wanted to know if that would work? as the array gets passed around, ...

47. Please Help - Using an Array from another class

Hello, I'm new to JAVA and I'm trying to pass an array from one class to another, but I can't get it right. I've been able to get individual values on at a time. If any one can help me out and give me a quick sample of how to do it, I've done this below. Is it as simple as ...

48. array questions and classes

49. Problem running a program practicing with Arrays and Classes

Hello all. I am having a problem running my program. It produces no output and goes on infinitely. I can't figure out what the problem is. Any help spotting anything unusual with my code would be appreciated. Thanks. public class LetterInventory { public static void main(String[] args) { LetterInventory inventory1 = new LetterInventory("Brandon Peeples"); } private String data; int[] inventory = ...

50. Where do we use Arrays class?

51. Super simple question: When to use Class Array versus Class Arrays?

Thanks. I think I'll be using the utility class way more often than the reflection class - which looks a little hairy to deal with. One more question about Arrays Class. Look at this method: static int binarySearch(Object[] a, Object key) Searches the specified array for the specified object using the binary search algorithm. Is this method taking an array full ...

52. Simple example using copyofRange () from Arrays Class won't compile

Hi, I'm just trying to understand how to use this method. I keep getting "cannot find symbol" for fcseats = Arrays.copyofRange(schart,0,4) when I compile, why am I getting this error? I verified parameters in the API. import java.util.Arrays; /** *Exercise 7.19 in Java book */ public class Reservation { //original seating chart with both sets of seats combined private boolean [] ...

53. How to create an array of MY class

Nothing you put there is going to be right. The right-hand side of the expression produces a Waypoint. Just a Waypoint. It doesn't produce an array of Waypoints, so you can't assign it to an array of Waypoints. So that doesn't make sense. I'm guessing that, since you have a loop, your goal is to assign that Waypoint object to some ...

54. Reading arrays from different classes without getters and setters

I have 2 arrays in different classes. Cards[100] is in and has 47 elements Map[501] is in and has 3 elements I've been reading a lot about trying to avoid using getters and setters. I want to edit either array while in the opposite class, but how do I do this? For example, when I'm in the CardArray class, ...

55. Drawing multiple instances of one class with an array

I have been tryng to draw two objects from the same class on a JFrame for about 5 hours now:confused:, but the last object created overrides the others. For example I want to paint two objects from the class ball on one JFrame. I need to do this in an array, I have tried this with arrayLists and normal arrays from ...

56. Java class array

Hi! I have a program that should does what in the My problem is that I have to store every new "munkas" in an array. How should I do that? Java Code: import szuret.*; class Tester { public static void main(String[] args) { SzoloSzureteloMunkas munkas1 = new SzoloSzureteloMunkas("Bla",5000,100,0.7); SzoloSzureteloMunkas munkas2 = new SzoloSzureteloMunkas("Jnos",6000,120,0.6); System.out.println(munkas1.osszehasonlit(munkas2)); // helyes: Bela System.out.println(munkas2.getNev() + " ...

57. Help displaying an array from a seperate class

Help displaying an array from a seperate class Okay, What I'm trying to do is take data from an array in my main class, and display it in a different class. here is my main class: Java Code: public class CharCreate { public static void main(String args[])throws Exception { int AddSkillPoints = 5; int[] dials = new int[5]; dials[0] ...

58. How to create an array of MY class

59. Displaying an array using a method contained in another class.

Certainly, but be warned, they are kinda long: Java Code: /** * */ import java.util.*; public class BattleShip { public static void main(String[] args){ Scanner input = new Scanner(; System.out.println("Welcome to battleship\n\n"); char[][] ArrayPlayer= new char[10][10]; // Create an Array for the player Arrays MyPlayers = new Arrays(ArrayPlayer); // Set MyPlayers object to contain array ArrayPlayer, called from //Patrol ...

60. help adding to array from another class

public class TestFloorProgram { public void start() { System.out.println("Testing the Floor class"); System.out.println("\nExpected output:\n---------------"); System.out.println(" | Floor 0 | (A,1)(B,2)(C,3)(D,4)"); System.out.println(" | Floor 0 | (A,1)(C,3)(D,4)"); System.out.println(" | Floor 0 | (C,3)(D,4)"); System.out.println(" | Floor 0 | (C,3)"); System.out.println(" | Floor 0 |"); System.out.println("\nActual output:\n--------------"); Floor f1; f1 = new Floor(0); Person p1, p2, p3, p4; p1 = new Person("A", 1); ...

61. use array from one class in another class.

62. Help with custom class array

public class CollegeCourse { private String courseId; private int creditHours; private char grade; public CollegeCourse(String i, int h, char g) { this.courseId = i; this.creditHours = h; this.grade = g; } public String courseId(){return this.courseId;} public int creditHours(){return this.creditHours;} public char grade(){return this.grade;} public void setcourseId(String i){this.courseId = i;} public void setcreditHours(int h){this.creditHours = h;} public void setgrade(char g){this.grade = g;} ...

63. Extract an Array from a Class

Hi burrish, in main you can place the following code Input3 input = new Input3(); String [] arrayFromClass = input.getNextString(); for(String s:arrayFromClass){ System.out.println(s); } ############# you can modify the getNextString method to return an array of strings instead each string once. public String [] getNextString() { return input; } .. I hope this is what you are looking hope this will ...

64. Using an array which is in a superclass

Ok so I have these two classes: Book and Encyclopedia. I want to create a method in Encyclopedia. I want it to modify an array which is an object in Book class. I'm not allowed to take the array as a method input like this: public void MethodName(Book [] a, String ...){ Instead, I have to find a way to call ...

65. The arrays class question

66. Arrays and Calling from Classes

private void calcPrintCost(){ //==todo==increment number of prints processed ++totalPrintsProcessed; //==todo==calculate printing cost here printCost = owner.getNbrPrints() * owner.getNbrRolls() * printRate; } {code} Problem is, in the printCost equation (printCost = owner.getNbrPrints(), etc) I am suppose to multiply the number of exposures (which can be certain numbers within the array) For example the user will select a film type and from there ...

67. Help with sending arrays to other classes

68. Need with calling arrays from a class

I have a project due soon. The project involes a hair solon with a set of Services, Prices, and Avg. Time spent with each service. I not even sure where to start. I have get and set methods for each date field. I know I need to build an constructor with arguments passing through them and store the data as arrays. ...

69. Class Composition with Array's - New to Java

70. Creating an Array from a different class

Hi everyone, I'm having a little trouble doing something and I wonder if someone could help. I have two different classes. One call Line which is an int Array of 6. and the other class called StoreLine which is an array of Lines objects. The problems is that the integers stored on a line is read from a ASCII file, using ...

71. Arrays with a Class Base Type

I am reading my text book and I have a question: suppose Date is a class then: Date[] holidayList = new Date[20]; The book says this creates 20 indexed variables of type, this does not create 20 objects of type Date. Can someone clear this up for me? I am thinking that you would have an array of 19 Date classes. ...

72. How to test a class with array which is being declared?

public static String nextDay(int index) { index+=1; return dayStrings[index]; } } The above compile well with no issue. Here is the problem which i need to seek your help, I had created a program to test the above program. But I am not sure how to test it. Here is what I had written : public class TestWD { public static ...

73. Array of a class?

74. classes and arrays

oCreate an object eg if num = 0 this will create an object in the first cell of the array: inv [num] = new Invoice(); oUse the dialog boxes and setters to capture the data as before but include the invoice number ie 1 to 3 as shown below in the dialog box. eg inv[num].setPartNumber(partNo); ?Print the Invoice heading as before ...

75. array of classes

76. arrays available in class

77. moving array between classes

Hello there. Right, i have 3 classes with which i am having a bit of trouble with. The first class, "Drawing," creates an array called componentList. Then, in another class called "DrawingCanvas" i have an instance of "Drawing" created. In this second class i have two methods which need to use the array from the first class. These methods are called ...

78. Class with array of another class

81. Help with Array in class

82. Newbie having problem with populating the array for class (bad description)

pvujic wrote: I know what is wrong, but I don't know how to fix it. Any solutions? I don't know what you're ultimately trying to accomplish with that line of code. You have some code that says "I'm going to put an array of Strings here", and then you have some code that says "Here's a Produkt to be used where ...

83. super class array

I have two classes - class A and class B - class B extends class A In class A I have class level variables declared as public static int d_jake = 0; public static String array_test[] = new String[50]; I had done some operations on them and changed their values I mean d_jake has some other value and array_test is filled ...

84. Working with Classes and Arrays

85. Help please! Using an array in another class

86. Execution a class from an array

Yes I meant a String array which contains the names of the 9 classes. I want to execute the method tArray[m].menu depending on the value of m. I may not have the syntax correct but what is needed is to execute the main method in one of 9 classes depending on an index m. Thank you

87. How to make a class an array

Hello, i am very confused as to how to make an array inside a class and use it from another class. For example, when making a "Book of hotties" where i would create entries in a book(objects) of hot women ,with parameters name, last name, phone number, and rating, and i am supposed to make a class for the book itself ...

88. Array of type class

I'm trying to make an array of objects of a class I've written called Order. I declare the array like this Order[] order = 99; As I understand it, this should make an array with 99 elements, each of type Order but I get the following error incompatible types found : int required : resturanttest.Order[] I am using NetBeans 6.5 IDE. ...

89. Calling an array from a different class

90. Arrays in other classes

You dont need to use arrays for the class. Think about it , A Person has a name and a code. So one String and one int should be enough to represent a person ,hence your Person class will need just those 2 variables . ( String name , int code ) Now write a public method that will take in ...

91. How to use array of Point Class

92. Input into an array of classes from a csv file...?

Sorry for the typos, didn't notice. - read a the line - split it into a String array as shown - if you get three items: - grab the first, trim it and use it as the first argument - grab the second, trim it, parse it using a method from Integer class, use the result as the second argument - ...

93. 2 classes needing to share the same array

I am not going to post any code this time, just see if i can get any suggestions. I have no problem in passing objects from a class into a method within that class but now i have a new problem. I have a database class which ask the user for inputs which are stored in an array. I have then ...

94. Feeding an Array into a Method in the Class

95. Storing in an array from my own created class

Hi, Here I am again with more questions. I am grovelling for help. I am working on a program in Netbeans 5.5.1 where I created a class called Student that gets and sets Last Name, First Name and Student ID. Now the program to run as a samle of this class will store the first Student I get and put it ...

96. howto instatiate array of inner classes

Hi, I couldn't find the syntax for doing this. I just want to instantiate an array of inner classes (non-static). It says '(' expected. Here is a small sample: public class test_inner { public class inner1 { } public inner1 inner1_inst; public class inner2 { } public inner2[] inner2_ar; public static void foo() { test_inner inst = new test_inner(); // OK ...

97. How to extend a JAVA class array?

Reason: The application programmer doesnt need to know the real model structure Id like to change later on when there will be new needs, but dont change the API I am looking for a kiss solution (keep it simple and stupid), so no academic thing like e.g. a factory pattern. Is there a (general) simple solution I was too blind ...

98. transfer arrays between classes

as you might have noticed for the last part (plz look at the code right at the end of the score class). after it says /** * Create and show the GUI. */ " i tried to return the array names players but that did not happen. what i had before i had the array trouble was :::: this part ...

100. Array class lookup  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.