aspose file tools*
The moose likes Beginning Java and the fly likes problem outputting Lists array contents to console Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "problem outputting Lists array contents to console" Watch "problem outputting Lists array contents to console" New topic
Author

problem outputting Lists array contents to console

Michael Gordon
Greenhorn

Joined: Nov 01, 2011
Posts: 19

Hello Gents/Ladies,

I'm having an issue getting my List<int[]> Array to output to the console (line 58). The output I get is 'Row = [I@61de33', what I'm trying to get is a list of all the values held within the array in each row respectively.
I'm just not sure what methods I am supposed to use to print this to console or how I should access each row and element directly. Any suggestions to point me in the right direction are welcomed.

The program I'm writing is supposed to take cipher texts, seperate the hex values, then convert to decimal and store in an array list so that I can then XOR their values and try to break the code, hopefully.
I initially wanted to XOR the hex values directly, but couldn't figure out how to do that and found XORing the decimal representation was a lot easier.

Many thanks in advance,

Michael

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61426
    
  67

That's what toString() produces for classes that don't override Object's. You'll need to emit the entries individually if you want more detail.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Michael Gordon
Greenhorn

Joined: Nov 01, 2011
Posts: 19

hmmm,

So I need to 'cast' the array list elements back to decimal when outputting them?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61426
    
  67

I said nothing about casting.
Michael Gordon
Greenhorn

Joined: Nov 01, 2011
Posts: 19

Ok,

So I managed to get the contents of the first array out in decimal format using the listIterator method.



I'm not entirely sure how I can iterate through each int[] Array row of an arraylist tho. I'm having a go at it just now, I may be some time

Thanks for the prompt response Bear.


Thanks,

Michael
Michael Gordon
Greenhorn

Joined: Nov 01, 2011
Posts: 19

well, I'm stumped. Tried a few things now and can't seem to iterate my list.

I thought I'd be able to simply loop through each row like this: http://stackoverflow.com/questions/2707357/how-to-create-dynamic-two-dimensional-array-in-java

I always seem to have this problem when using dynamic arrays. If this were a normal array, I would have been able to loop through and retrieve the elements no problem. I'm not so sure I'm using the arraylists correctly or whether I'm treating them the same as a normal one dimensional array. Any pointer would be great, I've been stuck with this problem all day and haven't been able to make these arrays work for me.


Michael
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18657
    
    8

Michael Gordon wrote:I'm not entirely sure how I can iterate through each int[] Array row of an arraylist tho.


Come on. You know perfectly well how to iterate through an int[] array. I'm sure of that.

But you seem to think that an int[] array is somehow different if you got it out of an ArrayList. It isn't. It's just an ordinary int[] array, so there's nothing stopping you from writing the everyday code to iterate through it and print its entries.

I'm not sure what you meant about "dynamic" and "ordinary" arrays but it looks to me like you're inventing distinctions where none exist. An array is an array no matter how you created it or what objects have references to it.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40



From your code, it looks like every int array in your list is an array of size one -- what is the purpose of using int arrays if each array has exactly one element? Wouldn't it be better to have a list of integers instead of a list of int arrays?

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Michael Gordon
Greenhorn

Joined: Nov 01, 2011
Posts: 19

Hi Bear/Paul/Henry,

I appreciate all the pointers guys, but not sure I'm making my intentions clear as I'm getting a bit bogged down with understanding how to move data in and out of the arrays.

Essentially, what I'm trying to achieve is this:

Take one of the ten ciphertext, break it into hex chunks, then add each of those chunks to an array of dynamic size (as the ciphertexts are of differing lengths), then add that row of hex to an int[] array (as the number of rows are constant) or a dynamic ArrayList if possible to choose 2 random rows when extracting the data, if this is possible? Once I have each ciphertext broken into chunks and in seperate rows of my array, I can then convert each row into ASCII(UTF-8) and output each elements value as a character (putting this into a temp array for display only), once I have this data, I can then XOR one row against data in another row. The XOR data can then be converted back into ASCII (UTF-8) character sets and this should then provide me with with information I can work with. The problem I had with XORing is that I couldn't XOR the hex values ( using xor = valueA ^ valueB) and had to convert them into integers to allow me to do this, which is why I'm trying to figure out how to use and transfer data to and from dynamically sized arrays.

Well, that's the plan anyway, but I've been struggling with how to get these arrays populated and also how to get the data back out of them. I don't fully understand how the dynamic (ArrayList) arrays work in this way and have been going round in circles trying to get it working (I know, I know, welcome to the world of programming right ). Perhaps there is a better way of doing this than the way I'm approaching the problem?

Thanks,

Michael
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8008
    
  22

Michael Gordon wrote:I appreciate all the pointers guys, but not sure I'm making my intentions clear as I'm getting a bit bogged down with understanding how to move data in and out of the arrays.

I suspect you're overthinking this.

It seems to me that you have two problems:
1. Display.
2. Cracking the code.
and the two are NOT related.

If those cipher texts are indeed huge numbers, and you want to treat them as such, my suggestion would be to convert them to BigInteger's,
which already have an xor() method, and several methods for display.

How you proceed from there is up to you. I'm no 3rd millenium Raffles.

Winston

BTW: I strongly urge you to break up those enormous lines. It makes this thread very hard to read.


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Michael Gordon
Greenhorn

Joined: Nov 01, 2011
Posts: 19

Hi Winston,

I've shortened the hex values to allow the browser to display the messages in a more readable manner.

The cipher strings are just hex values that represent ASCII characters, I need to break each string down into sets of 2 i.e. a1b2c3d4e5 becomes a1, b2, c3, d4, e5. I think you are right tho, the 2 problems of display and code cracking are not related, think I'm still trying to program in a procedural sense rather than object orientated and the two problems are becoming one (big headache). I had to look up 3rd millenium lol, my programmind design style is probably more like 1st jurassic.

I'll look into BigInteger and see if I can manipulate the data easier with its methods.

Kind regards,

Michael
Michael Gordon
Greenhorn

Joined: Nov 01, 2011
Posts: 19

Ok,

So looks like BigInteger is the way to go for xor'ing my data. But I'm still having problems using arrayslists. I have used a multidimensional array to hold my hex data chunks, which seems to work fine, but the problem with using normal arrays is that I need to declare the length of each row before I can use it. This is causing problems because the empty elements are padded with NULL entries. For example, when I try to pass row 0 element 1 AND row 2 element 1 to the xor function, it works fine up until it hits a NULL entry, because BigInteger throws an exception when it is passed a NULL as an argument. I tried to compensate for this by creating an if statement that only performs the xor until it hits a NULL element, when it hits NULL, it should break. I've spent nearly 3 days trying to figure out what should be a simple thing to do, but I'm really struggling.

Can someone help me out please?

 
Consider Paul's rocket mass heater.
 
subject: problem outputting Lists array contents to console