Home Answers Viewqa Java-Beginners plz try to clear my doubt for shuffling multi-dimensional array

 
 


Kalpana
plz try to clear my doubt for shuffling multi-dimensional array
1 Answer(s)      2 years and 5 months ago
Posted in : Java Beginners

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 Pages:
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
Arrays -- Multi-dimensional
Java NotesArrays -- Multi-dimensional All arrays in Java are really linear, one-dimensional arrays. However, you can easily build multi-dimensional arrays... the row (which is a one-dimensional array itself), and the second subscript selects
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
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
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
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
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
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
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
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
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
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
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
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
doubt about JMS selector
doubt about JMS selector  Hi! , i have a little problem with message selector in JMS api. I'am try develop a request and response with JMS queue, but I didnÃ?´t get success. in my case, i send a message to server, server
doubt about JMS selector
doubt about JMS selector  Hi! , i have a little problem with message selector in JMS api. I'am try develop a request and response with JMS queue, but I didnÃ?´t get success. I use this reference site like guide. in my
TIME SERIES DOUBT
we do that ??///// plz helppp plz if u have not understood my question then plz ask again me abt it but plz reply...TIME SERIES DOUBT  HI.................... In my project i am using
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
doubt on synchronized block in java
. I think you got my doubt. I request you to clarify my doubt based on below...doubt on synchronized block in java  Hi ! some people are feeling bore on my regular questions on threads. Do not feel bore on my regular questions.I
PHP Push MultiDimensional Array
a multi-dimensional array into another array, a single element into an array...://roseindia.net/tutorial/php/phpbasics/PHP-Array-Push.html PHP Push Multi-Dimensional Array Example : <?php $array1=$array3=array(1,2,3,4,5,6
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
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
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
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
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
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
Generate shuffling in the specified list
void main(String args[]) { // create an array of employee names of string...", "Komal"}; // create list for the specified array of employee. List
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     
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
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
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
plz answer - Java Beginners
plz answer   Write a Binary Search program that searches an array of ordered data. Compose an ordered array of 500 integers that contains..., 89, ...  Hi Friend, Try the following code: import java.util.
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
Crystal clear reports
Crystal clear reports  what is crystal clear and i-text reports in java? plz give me full information
plz help - Java Beginners
plz help  i have to programs and it takes too long to run them so i..... but i dont know how to aplly that on my 2 programs: the first code...(); } public void run(){ try { System.out.println(s
java doubt
can also use throws clause on the surrounding method instead of try and catch
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
big doubt
+ "and broadcast_end_time<=" + l; String msg = ""; try
plz give me answer plz
plz give me answer plz  writw a programme to find rank from an array using doubledimmensionalarray
Clear UIWebView cache iPhone
Clear UIWebView cache iPhone  Hi, In my iPhone application ..i am using a UIWebView to load different URL on it. But i am afraid that it 's not releasing the memory. Can anyone please explain me how to load and release
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
C and C++ books-page4
indices (in a multi-dimensional array, e.g. names[3][0][2]). The first element...; The Static and Dynamic allocation of multi-Dimensional arrays An array in C is a region of memory in which the elements (chars, ints, etc.) can
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_key General Format
Random Numbers - shuffling
Java NotesRandom Numbers - shuffling A standard approach to shuffling the elements of an array is to write some code as described below. As of Java 2... is described at the bottom. Shuffling: Random numbers without replacement
Download.jsp Urgent plz - JSP-Servlet
in my database.. Only the file name are present in my database which has been... con=null; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con... me immediately.. This is my kind request to whole Roseindia team.. Thanks
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
How to clear dos screen just like cls in dos - Java Beginners
How to clear dos screen just like cls in dos  You said we have to write bat bile. so every time i have to call that file in my java program am i...) { try { Runtime rt = Runtime.getRuntime(); rt.exec("cmd.exe /C start C

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.