List of usage examples for java.lang String String
public String(StringBuilder builder)
From source file:Main.java
public static void main(String[] args) throws Exception { Set<String> set = new HashSet<String>(); String str = "java2s.com"; set.add(str);/*from w w w.j a v a2s. co m*/ Field stringValue = String.class.getDeclaredField("value"); stringValue.setAccessible(true); stringValue.set(str, str.toUpperCase().toCharArray()); System.out.println("New value: " + str); String copy = new String(str); // force a copy System.out.println("Contains orig: " + set.contains(str)); System.out.println("Contains copy: " + set.contains(copy)); }
From source file:MultiArray1.java
public static void main(String args[]) { // int array[][] = {{1,2,3}, {4,5,6}, {7,8,9}}; // int []array[] = {{1,2,3}, {4,5,6}, {7,8,9}}; // System.out.println(array[0][0]); // System.out.println(array[1][0]); // System.out.println(array[2][0]); // System.out.println([0][0]array); // System.out.println([1][0]array); // System.out.println([2][0]array); Object events[][] = { { new Integer(1452), new String("Italy") }, { new Integer(1472), new String("b.jpg") }, { new Integer(1483), new String("Hr") }, { new Integer(1495), new String("Pte") }, { new Integer(1503), new String("m.jpg") }, { new Integer(1519), new String("F") } }; }
From source file:Main.java
public static void main(String[] args) throws Exception { PipedOutputStream out = new PipedOutputStream(); PipedInputStream in = new PipedInputStream(); // connect input and output in.connect(out);//from www . j a v a 2 s . c o m // write something out.write(70); out.write(71); // read what we wrote into an array of bytes byte[] b = new byte[2]; in.read(b, 0, 2); System.out.println(new String(b)); in.close(); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider()); KeyGenerator generator = KeyGenerator.getInstance("AES", "BC"); generator.init(128);/* ww w .j av a 2 s. co m*/ Key keyToBeWrapped = generator.generateKey(); System.out.println("input : " + new String(keyToBeWrapped.getEncoded())); // create a wrapper and do the wrapping Cipher cipher = Cipher.getInstance("AES/ECB/NoPadding", "BC"); KeyGenerator keyGen = KeyGenerator.getInstance("AES", "BC"); keyGen.init(256); Key wrapKey = keyGen.generateKey(); cipher.init(Cipher.ENCRYPT_MODE, wrapKey); byte[] wrappedKey = cipher.doFinal(keyToBeWrapped.getEncoded()); System.out.println("wrapped : " + new String(wrappedKey)); // unwrap the wrapped key cipher.init(Cipher.DECRYPT_MODE, wrapKey); Key key = new SecretKeySpec(cipher.doFinal(wrappedKey), "AES"); System.out.println("unwrapped: " + new String(key.getEncoded())); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { int port = 0; InetAddress group = InetAddress.getByName("127.0.0.1"); MulticastSocket ms = new MulticastSocket(port); ms.joinGroup(group);/* w w w .j a va 2 s . c o m*/ byte[] buffer = new byte[8192]; while (true) { DatagramPacket dp = new DatagramPacket(buffer, buffer.length); ms.receive(dp); String s = new String(dp.getData()); System.out.println(s); } // ms.leaveGroup(group); // ms.close(); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { KeyGenerator keyGenerator = KeyGenerator.getInstance("Blowfish"); keyGenerator.init(128);/*ww w . j a va 2 s . c om*/ SecretKey key = keyGenerator.generateKey(); Cipher cipher = Cipher.getInstance("Blowfish/ECB/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, key); byte[] cipherText = cipher.doFinal("This is a test.".getBytes("UTF8")); System.out.println(new String(cipherText)); }
From source file:MainClass.java
public static void main(String[] args) throws NoSuchAlgorithmException { int numBytes = (new Integer("1111")).intValue(); long seed = 01; if (args.length > 1) seed = (new Long("1111111111")).longValue(); SecureRandom srand = SecureRandom.getInstance("SHA1PRNG"); if (seed != 01) srand.setSeed(seed);//from w w w . ja v a 2s . c o m byte[] bytes = new byte[numBytes]; srand.nextBytes(bytes); System.out.println(new String(bytes)); }
From source file:Main.java
public static void main(String[] args) { String palindrome = "Dot saw I was Tod"; int len = palindrome.length(); char[] tempCharArray = new char[len]; char[] charArray = new char[len]; // put original string in an array of chars for (int i = 0; i < len; i++) { tempCharArray[i] = palindrome.charAt(i); }/* w ww. j a v a2 s . c o m*/ // reverse array of chars for (int j = 0; j < len; j++) { charArray[j] = tempCharArray[len - 1 - j]; } String reversePalindrome = new String(charArray); System.out.println(reversePalindrome); }
From source file:Main.java
public static void main(String[] args) { JPanel ui = new JPanel(new BorderLayout(2, 2)); ui.setBorder(new EmptyBorder(4, 4, 4, 4)); JPanel controls = new JPanel(new BorderLayout(2, 2)); ui.add(controls, BorderLayout.PAGE_START); String s = new String(Character.toChars(8594)); String[] items = { "Choice: right " + s + " arrow" }; JComboBox cb = new JComboBox(items); controls.add(cb, BorderLayout.CENTER); controls.add(new JButton("Button"), BorderLayout.LINE_END); JSplitPane sp = new JSplitPane(JSplitPane.VERTICAL_SPLIT, new JTextArea(4, 40), new JTextArea(4, 40)); ui.add(sp, BorderLayout.CENTER); JFrame f = new JFrame("Stretch Combo Layout"); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); f.setContentPane(ui);/*from w ww .j ava 2s . c om*/ f.pack(); f.setLocationByPlatform(true); f.setVisible(true); }
From source file:UDP0.java
public static void main(String[] args) throws Exception { byte[] ary = new byte[128]; DatagramPacket pack = new DatagramPacket(ary, 128); if (args[0].charAt(0) == 'r') { // read// w ww . jav a2 s . com DatagramSocket sock = new DatagramSocket(1111); sock.receive(pack); String word = new String(pack.getData()); System.out.println("From: " + pack.getAddress() + " Port: " + pack.getPort()); System.out.println(word); sock.close(); } else { // write DatagramSocket sock = new DatagramSocket(); pack.setAddress(InetAddress.getByName(args[1])); pack.setData(args[2].getBytes()); pack.setPort(1111); sock.send(pack); sock.close(); } }