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

Ads









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
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
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
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
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
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
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
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     
Array in Java
. Different types of array used in Java are One-dimensional, Two-dimensional and multi...An Array is the static memory allocation that holds a fixed number of values of same type in memory. The size or length of an array is fixed when the array
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
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
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
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
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
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
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
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
Crystal clear reports
Crystal clear reports  what is crystal clear and i-text reports in java? plz give me full information
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
plz give me answer plz
plz give me answer plz  writw a programme to find rank from an array using doubledimmensionalarray
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'

Ads