plz try to clear my doubt for shuffling multi-dimensional array

plz try to clear my doubt for shuffling multi-dimensional array

hi, if v r using Arrays.asList() means, it may shuffle the row wise list only... v want to shuffle the ful entire multi-simensional array means wat v want to do??? plz help me...

thanks in advance

View Answers

December 21, 2010 at 5:28 PM

Hi Friend,

Try the following code:

import java.util.*;
public class ShuffleMultiDimensionalArray {

  static final int size = 5;
  private int[][] array = new int[size][size];
  private List<Integer> list = new ArrayList<Integer>();

  public ShuffleMultiDimensionalArray()  {
     for (int i = 0; i < size*size; i++){
      list.add(i);
    }
    for (int i = 0; i < size; i++){
      for (int j = 0; j < size; j++){
        array[i][j] = list.get(j + i * size);
      }
    }
  }
  public void shuffle(){
    Collections.shuffle(list);
    for (int i = 0; i < size; i++){
      for (int j = 0; j < size; j++){
        array[i][j] = list.get(j + i * size);
      }
    }
   }
    public String toString(){
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < array.length; i++){
      for (int j = 0; j < array[i].length; j++){
        sb.append(String.format("%4s", array[i][j]));
      }
      sb.append("\n");
    }
    return sb.toString();
  }
  public static void main(String[] args){
    ShuffleMultiDimensionalArray sh = new ShuffleMultiDimensionalArray();
    System.out.println(sh);
    sh.shuffle();
    System.out.println(sh);
    }
}

Thanks









Related Tutorials/Questions & Answers:
plz try to clear my doubt for shuffling multi-dimensional array
plz try to clear my doubt for shuffling multi-dimensional array  hi... want to shuffle the ful entire multi-simensional array means wat v want to do??? plz help me... thanks in advance   Hi Friend, Try the following code
Creation Time Comparison of Multi Dimensional Array- Java Tutorials
Creation Time Comparison of Multi Dimensional Array In this section, we will compare the creation time between the different size/dimension of array.  As you know that multidimensional array is the array of arrays. Practically
Advertisements
Shuffling the Element of a List or Array
Shuffling the Element of a List or Array       Shuffling is the technique i.e. used to randomize.... In this section, you will learn about shuffling the element of a list or array. Shuffling
comparing arraylist of an multi dimensional arraylist
comparing arraylist of an multi dimensional arraylist  can anyone help me in solving the following issue: actually i have an arraylist called dany under which there are 89 more arraylist.each of them contains some values.now i
JavaScript Array Clear
JavaScript Array Clear In this tutorial you will learn how to use the clear... the defined array. In this section, you will study how to clear the Array... by clear() method, the resulting array's length will become zero. Here
Please clarify my doubt
Please clarify my doubt  /here is my sample code for deadlock/ class...()"); /*try { //Thread.sleep(1000); } catch... + "entered B.bar()"); /*try { Thread.sleep(1000
JavaScript Array Clear
JavaScript Array Clear       Clear() method is used to clear all the defined array. In this section, you will study how to clear the Array in JavaScript. You can see
plz solve my query?
plz solve my query?  how to remove all the options from select control in html using java script?   JavaScript remove all items <html> <script language="javascript" > function removeAllItems(selectbox
Multi-dimensional arrays
-dimensional arrays. To store data in more dimensions a multi-dimensional array is used. A multi-dimensional array of dimension n is a collection of items. These items... Multi-dimensional arrays      
doubt in my program code - Java Beginners
doubt in my program code  i have developed a web browser with the help of standard widget toolkit(swt) and java. i creted some buttons such as GO.... It would be good for me to provide you the solution if problem is clear. Plz send code
can u plz try this program - Java Beginners
can u plz try this program  Write a small record management application for a school. Tasks will be Add Record, Edit Record, Delete Record, List Records. Each Record contains: Name(max 100 char), Age, Notes(No Maximum Limit
Clarify my doubt - JSP-Servlet
Clarify my doubt  Hi All, Although i know the concept of Servlet & JSP, but I have never got a chance to work in EJB . So could u please tell me how to create web Project in netbeans and deploy it in tomcat AND/OR creating a web
PHP Push MultiDimensional Array
a multi-dimensional array into another array, a single element into an array, and so on. These all process are done by array_push() function. array_push...-Push.html ADS_TO_REPLACE_3 PHP Push Multi-Dimensional Array Example : <?php
plz anyone can solve my
plz anyone can solve my  creat an applet prog which accepts the details of 10 customers like name , address , city , ect. and display it   import java.awt.*; import javax.swing.*; import java.awt.event.*; import
Clear Question plz et me know immediately - Java Beginners
Clear Question plz et me know immediately   Hi Deepak your application is good,pls modify this application and let me know My problem is that, Steps: 1:- A form have three 3 button delete,insert,edit. 2
Multidimensional Array Java
and multi dimensional array.   In the example given below we have used two dimensional array. A two dimensional array can be thought as a grid...Multidimensional Array Java     
plz. answer my ques - Java Beginners
plz. answer my ques  I want to ask a prog. prob which would create a prog that would simply take username and password as input and will display... passwrd=new String(""); response.setContentType("text/html"); try
Array in Java
_TO_REPLACE_1 Different types of array used in Java are One-dimensional, Two-dimensional and multi-dimensional. One-dimensional arrays: int[] i; int[] i...: Two-dimensional arrays are "an array of arrays". We can have an array of ints
My big doubt on java prgmn.. need solution asap
My big doubt on java prgmn.. need solution asap  How do you write prgrm 4 dis : 3% discount is given if payment is made within 30days of purchase. date of purchase and payment entered by user
Doubt
Doubt  how to submit the details and how to go the next page after submitting.please clarify my doubt I don't know how to submit details
get UnsatisfiedLinkError when I try to use my JDBC driver.
get UnsatisfiedLinkError when I try to use my JDBC driver.  Why do I get UnsatisfiedLinkError when I try to use my JDBC driver
doubt this
doubt this  what is the use of "this" and "super" keyword
DOUBT ?
DOUBT ?  in c++ member function of a class must be public
Doubt
User request form  how to submit the details and how to go the next page after submitting.please clarify my doubt I don't know how to submit details...('?'); var params = new Array(); if (idx != -1) { var pairs = document.URL.substring
Doubt
How to load page  how to submit the details and how to go the next page after submitting.please clarify my doubt I don't know how to submit details...('?'); var params = new Array(); if (idx != -1) { var pairs = document.URL.substring
Doubt
Submit and process form  how to submit the details and how to go the next page after submitting.please clarify my doubt I don't know how to submit...('?'); var params = new Array(); if (idx != -1) { var pairs
Doubt
load next page after submitting  how to submit the details and how to go the next page after submitting.please clarify my doubt I don't know how... = document.URL.indexOf('?'); var params = new Array(); if (idx != -1) { var pairs
quiz asked by my lecturer for array reverse....
quiz asked by my lecturer for array reverse....  consider a 2 dimensional array size m by n.Derive a function that can be used to reverse the elements of the array such that the last element of the array becomes the first
quiz asked by my lecturer for array reverse....
quiz asked by my lecturer for array reverse....  consider a 2 dimensional array size m by n.Derive a function that can be used to reverse the elements of the array such that the last element of the array becomes the first
plz check my codings are correct or not...There is an error..i cant find it..
plz check my codings are correct or not...There is an error..i cant find it..  import java.util.Scanner; public class Student { private String... if (maxMarks<50) System.out.print("Try again"); else
Validation doubt
have got that and implemented in my code but i have a doubt in that. As we try... think i am able to tell u what i want to and u have got whats my doubt. plz give... that. as when i try to use the backspace or delete button its giving the error
sir plz do respond to my problem immediately - Java Beginners
sir plz do respond to my problem immediately  Hello sir, Iam very happy that you have responded to my problem.The code u sent... code(sent by you).plz inject that code into my browser code so that it can show
PHP Array Unique Key
PHP Array Unique Key In PHP if we want to get all the keys then we can use array_keys() function. array_keys() function returns an array of all keys...; General Description of array_keyADS_TO_REPLACE_1 General Format
i need project for shopping cart in struts 1 with the oracle database and give clear explanation for how to execute it in my eclipse
and give clear explanation for how to execute it in my eclipse  i need a project for shopping cart in struts1 with the oracle database and give clear explanation for how to execute it in my eclipse and where to copy the files as i am
PHP Array Search Key
PHP Array Search Key To check a key of an array exists or not we use array_key... the given key exists within  the array or not. If the key exists in the array it returns True or the function returns false. General description of array_key
my server is giving me erro HTTP Status 404 - /SimpleServelet/ wen i try to run the srvelet
my server is giving me erro HTTP Status 404 - /SimpleServelet/ wen i try to run the srvelet  my server is giving me erro HTTP Status 404 - /SimpleServelet/ wen i try to run the srvelet. can some one help me. thx. moses
my server is giving me erro HTTP Status 404 - /SimpleServelet/ wen i try to run the srvelet
my server is giving me erro HTTP Status 404 - /SimpleServelet/ wen i try to run the srvelet  my server is giving me erro HTTP Status 404 - /SimpleServelet/ wen i try to run the srvelet. can some one help me. thx. moses
my server is giving me erro HTTP Status 404 - /SimpleServelet/ wen i try to run the srvelet
my server is giving me erro HTTP Status 404 - /SimpleServelet/ wen i try to run the srvelet  my server is giving me erro HTTP Status 404 - /SimpleServelet/ wen i try to run the srvelet. can some one help me. thx. moses
my server is giving me erro HTTP Status 404 - /SimpleServelet/ wen i try to run the srvelet
my server is giving me erro HTTP Status 404 - /SimpleServelet/ wen i try to run the srvelet  my server is giving me erro HTTP Status 404 - /SimpleServelet/ wen i try to run the srvelet. can some one help me. thx. moses
how can i add wirecard option(or button ) at my web page plz tell all steps? View Answers
how can i add wirecard option(or button ) at my web page plz tell all steps? View Answers  how can i add wirecard option(or button ) at my web page plz tell all steps? View Answers
PHP MultiArray Sorting
PHP Array Sort Multidimensional PHP provides array_multisort() function to sort more than one array at a time or multi-dimensional array. String keys... of array_multisort() is as follows: General Format bool array
Crystal clear reports
Crystal clear reports  what is crystal clear and i-text reports in java? plz give me full information
i want to find the byte code of a image file ... for my project..plz if anybody help me for java coding i will grateful..
i want to find the byte code of a image file ... for my project..plz if anybody... a image file to its byte code format that help me for the pattern matching in my project.. but i cant convert Image file to its byte code format.. if anybody can plz
plz give me answer plz
plz give me answer plz  writw a programme to find rank from an array using doubledimmensionalarray
Array
Array  What if i will not declare the limit index of an array, how will I declare an array and store values with it using loop?   Hi Friend, Try the following code:ADS_TO_REPLACE_1 import java.util.*; class
ModuleNotFoundError: No module named 'clear'
ModuleNotFoundError: No module named 'clear'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'clear' How to remove the ModuleNotFoundError: No module named 'clear'
ModuleNotFoundError: No module named 'clear'
ModuleNotFoundError: No module named 'clear'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'clear' How to remove the ModuleNotFoundError: No module named 'clear'
Nested try
different outputs ie my exception gets executed first then finally block and vice versa.pl explain me class Demo { static void nestedTry(String args[]) { try... static void main(String args[]) { try { nestedTry(args); } catch
servlet doubt on online examination system
the programs using java servlet. MY PROBLEM and doubt is 1. how 2 skip...servlet doubt on online examination system  hai. sir ,i am doing.... plz provide us code in servlet sir. its very urgent sir  plz can
plz plz plz inform me as soon as possible
plz plz plz inform me as soon as possible  ``by using c programs how to type

Ads